1؎: The noble Companions (Sahabah) and the righteous predecessors (Salaf Salihin) used to sleep in the mosque, therefore there is no doubt regarding its permissibility. The statement of Ibn Abbas radi Allahu anhuma is correct that whoever has a house in the same neighborhood should not spend the night in the mosque; Imam Malik is also of this opinion.
Explanation & Benefits
Shaykh Dr. Abdur Rahman Freywai
1: The Companions (Sahabah) and the righteous predecessors (Salaf Salihin) used to sleep in the mosque; therefore, there is no doubt regarding its permissibility. The statement of Ibn Abbas radi Allahu anhuma is indeed correct that whoever has a house in the same neighborhood should not spend the night in the mosque. Imam Malik is also among those who hold this view.
Source: Sunan al-Tirmidhi – Majlis ‘Ilmi Dar al-Da‘wah, New Delhi Edition, Page: 321
´It was narrated that Ibn 'Umar said:` "We used to sleep in the mosque at the time of the Messenger of Allah."
Maulana Ataullah Sajid
If a traveler or any other person, due to necessity, sleeps in the mosque, it is permissible, but it should not be made a habit. Similarly, if a person who has come for prayer falls asleep while sitting and waiting for the congregation, there is no harm in it.
Source: Commentary on Sunan Ibn Mājah by Mawlānā ‘Atā’ullāh Sājid, Page: 751