Origin of the greeting "Sweet dreams"
Solution 1:
The OED has the interjection as "a farewell to someone going to bed" from the 20th century:
1908 Sears Roebuck Catal. 198/1 Tenor Solos..Good Bye, Sweet Dreams, Good Bye.
But it goes back until at least the 19th and possibly 18th centuries.
John Wolcot, writing under the pseudonym of Peter Pindar, used it in his poem "Orson and Ellen; A Legendary Tale" published in 1801:
Also from 1801 in The infernal Quixote (Page 287) by Charles Lucas:
In the March 1776 of The Universal Magazine was published "The Serenade. A Pastoral Tale. From the German of Gesner", where the shepherd Daphnis watches over his beloved as she sleeps and sings:
The same tale appears in 1776's as Idyl XI, "Daphnis" in New Idylles by Gessner translated by W. Hooper. Salomon Gessner was a Swiss painter and poet and first wrote "Daphnis" in 1754.
Dreams had been referred to as sweet much earlier, such as in Francis Bacon's Wisdom of the Ages in 1680 (originally from 1609 in Latin, "Done into English by Sir Arthur Gorges Kt."), and 1709 in The Works of Sir John Suckling: Containing His Poems, Letters and Plays.
Solution 2:
The phrase may have gained currency during the 17th century.
An early example of "Sweet dreams" can be found in the Jacobean play The Witch (1606~1616) by Thomas Middleton
Act 2 Sc 1 [Antonio's house]
"Enter Francisca.
FRANCISCA Good morrow, Gasper.
GASPERO Your hearty wishes, mistress, And your sweet dreams come upon you."
Solution 3:
Written around 900 B.C., Proverbs 3:24 says, "When thou liest down, thou shalt not be afraid: yea, thou shalt lie down, and thy sleep shall be sweet." Referring to a promise of the sweetness of sleep or dreams granted to those that followed God's commands.