Reference: Fataawa al-Lajnah ad-Daa.imah lil-Buhooth al-‘Ilmiyyah wal-Iftaa., – Volume 6, Page 291, Question 4 of Fatwa No.5795
Fataawa tata’allaq bi-Jamaa’ah al-Masjid – Question 18, Page 18
Question: What is the ruling regarding the one who points his legs towards the [direction of the] Qiblah in the masjid?
And is it permissible to eat and sleep in the masjid?
Response: There is no harm for the Muslim to stretch his legs or leg towards the Qiblah whether he is in the masjid or not. Also, there is no harm in him eating and sleeping in the masjid if he is in need of that. It is, however, befitting upon him to take care in keeping the masjid clean and if he were to have a wet dream whilst alseep in the masjid, he should hasten to leave [the masjid] as soon as he wakes up so as to take the [obligatory] ghusl as result of [his state of] janaabah.
And with Allaah lies all success and may Allaah send prayers and salutations upon our Prophet Muhammad (sal-Allaahu `alayhi wa sallam) and his family and his companions.