
Islamic scholars explain this ruling using clear proofs. Hazrat Abdullah bin Umar (RA) said that during the time of the Prophet ﷺ, he used to sleep in Masjid Nabawi even though he was not married. Hazrat Sahl bin Sa’d (RA) also narrated that the Prophet ﷺ once found Hazrat Ali (RA) sleeping in the mosque and told him to get up. These narrations show that sleeping in the mosque is allowed.
Because of these evidences, the jurists say that a mosque is mainly a place for prayer and dhikr, but sleeping in it is permissible without any dislike. It is better if a person sleeps with the intention of i‘tikaf, but it is not required. Sleeping in the mosque for a good Islamic reason is also valid. However, a person must make sure that his sleeping does not block space for anyone who wants to pray.
Islamic scholars like Imam Nawawi and Allamah Bajuri also stated that sleeping in the mosque is allowed as long as it does not disturb worshippers.
This fatwa clearly shows the Islamic ruling that sleeping in the mosque is permitted and not disliked.