All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
We don't know any authentic Hadeeth from the Prophet or a saying of any of his companions specifying the direction of the legs or the head while the person is sleeping.
Nonetheless, some jurists wrote in their books that facing the Qiblah while sleeping is desirable. Then, naturally one's legs will not be in the direction of Qiblah. We do not know the reference for this; they might have compared the condition of a sleeping person to that of a dead person who should be faced to the Qiblah or they might have concluded this point considering the merits and virtues of the Qiblah.
What is proved from the Prophet is that when he went to bed, he used to sleep on his right side and then say, “Allahumma aslamtu nafsi ilayka, wa wajjahtu wajhi ilayka, wa fawwadhtu amri ilayka, wa alja'tu dhahri ilayka, raghbatan wa rahbatan ilayka. Laa malja-a wa laa manja minka illa ilayka. Aamantu bikitabikal-ladhi anzalta wa nabiyyika al-ladhi arsalta” (O Allah! I have submitted my face (or, myself) to You, and I am under Your Command (i.e., depend upon You in all my affairs), and put my back to (i.e., trust in) You expecting Your reward and fearing Your punishment. There is no fleeing from You and no refuge but with You. I believe in the Book (i.e., the Quran) You have revealed and in Your Prophet (Muhammad) You have sent.) Allah's Messenger said: “Whoever recites these words (before going to bed) and dies the same night, he will die on the Fitrah (natural predesposition upon which Allah created mankind; i.e. on Islamic religion (as a Muslim).”
Hudhayfah said:
“When the Prophet went to bed at night, he would put his hand under his cheek and then say, “Allahumma bismika amootu wa ahya”. (O Allah! In your name I die and I live), and when he got up, he would say, “Al-Hamdu Lilaahi al-ladhi ahyaana ba'da maa amaatana, wa ilayhi an-nushoor.” (All thanks and praises be to Allah, who has given us life after causing us to die (i.e., sleep), and unto Him is the Resurrection.
For more benefit, please refer to Fatwa 90227.
Allah knows best.