I've tried to ask a very general question in the title, but I'll begin with the specific circumstance that gave rise to my question.
I was looking at the Maxwell House Haggadah and noticed this prayer (the Kiddush):
בָּרוּךְ אַתָּה יְיָ אֱלֹהֵינוּ מֶלֶךְ הָעוֹלָם, בּוֹרֵא פְּרִי הַגָּפֶן
The guide to the spoken form begins, “Bar-ruch a-taw A-do-noi...”.
This Haggadah has the blessing as “בָּרוּךְ אַתָּה יְהֹוָה” (etc.)
It was interesting to me that the Tetragrammaton is written in the text, though of course it is not intended to be spoken. I suppose my previous assumption had been that the Tetragrammaton would only occur in Biblical texts, and in later texts quoting or discussing those texts—i.e., where its use is ‘forced’ by fidelity to the Scriptures. This is a use of the Tetragrammaton where it doesn't seem to be required.
(A related question is why the Tetragrammaton is represented with its vocalization only in this case, and whether that is a common practice.)
So clearly my assumptions about when the Tetragrammaton would be used/written/represented are wrong. Is it the case that the word can be written relatively freely, just not pronounced? What principles restrict its use in non-Biblical literature?