Eating, drinking, and sleeping in the mosque without necessity is Makruh (disliked). However, there is allowance for a traveler and a person in Itikaf to eat, drink, and sleep in the mosque. Similarly, if a person has such a religious need that cannot be achieved without sleeping in the mosque—for example, achieving punctuality in congregational prayer, or getting the opportunity for Tahajjud, or if guarding the mosque is intended—then there is permission and allowance for him to sleep in the mosque as well. Some of the noble Companions (May Allah be pleased with them all) also used to sleep in the mosque for religious needs. (Aham Masail / Vol: 3 / Pg: 246)