Staying in Mosques for several days, and sleeping in them is permitted as long as the person is observing `Itikaf or there is a Da`wah purpose for staying there. However, it is discouraged and improper to take Mosques as a sleeping place.
Focusing more on this issue, we would like to furnish Muslims with the following Fatwa:
“If you go to a Mosque you may stay as long as you wish. You are only required not to say or do what is forbidden. Suppose you go to a Mosque and spend a few hours, you may offer your prayers when they are due and you may offer voluntary prayers and recite a short or a long passage from the Qur’an. After a while you may wish to just sit down and think or relax.
Sleeping in the Mosque is not forbidden. Indeed, it is permissible, and it is recommended in certain cases. The Prophet, peace and blessings be upon him, has encouraged us to do the Sunnah of I’tikaf, which means staying in the Mosque for an extended period, which may last for several days, particularly in the last ten days of Ramadan.
This means that a person may stay in the Mosque for several days. When he is done, he may go to his home to attend to his family’s needs and come back. He will be rewarded for that.
Having said that, we would like to conclude that using the Mosque as a sleeping place is not a good practice. Indeed, it is discouraged, because the Mosque is not meant for sleeping.”
May Allah guide us to the straight path to that which pleases Him, Amen.