In The Name of Allaah, The Most Merciful The Bestower of Mercy.
Aa’isha [may Allaah be pleased with her] narrated: There was a black slave girl belonging to an Arab tribe and they freed her but she remained with them. The slave girl said, “Once one of their girls (of that tribe) came out wearing a red leather scarf decorated with precious stones. It fell from her or she placed it somewhere. A kite (i.e. a medium to alarge long-winged bird of prey) passed by that place, saw it lying there and mistaking it for a piece of meat, flew away with it. Those people searched for it but they did not find it. So they accused me of stealing it and started searching me and even searched my private parts.” The slave girl further said, “By Allah! While I was standing (in that state) with those people, the same kite passed by them and dropped the red scarf and it fell amongst them. I told them, ‘This is what you accused me of and I was innocent and now this is it.'” Aisha added, ‘That slave girl came to Allah’s Messenger (ﷺ) and submitted in Islam. She had a tent or a small room with a low roof in the Masjid. Whenever she visted me, she had a talk with me and whenever she sat with me, she would recite the following, ‘The day of the scarf (band) was one of the wonders of our Lord, verily He rescued me from the disbelievers’ town’. `Aisha added, ‘Once I asked her, what is the matter with you? Whenever you sit with me, you always recite these poetic verses.’ So she told me the whole story'”. [Saheeh al-Bukhaari. Number 439]
Imaam Ibn Hajr [may Allaah have mercy upon him] stated:
*In the hadith is that it is permissible to stay overnight and sleep in the Masjid for those Muslims – whether a man or woman – who do not have a place to live if that would not lead to trouble.
*The permissibility of placing a covering in the Masjid by way of a tent and the like.
*To leave the land where a person is put to trial in the hope of relocating to a better place for oneself just as what happened to this woman.
*The virtue of migrating from the land of disbelief.
*Allaah’s response to the supplication of an oppressed person even if he (or she) is a disbeliever because the context of this hadeeth shows that she became a Muslim after arriving in Medeenah. Allaah knows best. (1)
Imaam Abdul Azeez bin Baaz [may allaah have mercy upon him] stated:
*This oppressed woman was aided by Allaah, for indeed Allaah aids a person if he (or she) is a disbeliever.
*Exit the Masjid if menses begin in the Masjid or stay out of necessity. (see footnote a)
*There is no harm in erecting a tent for a woman who is in need until a safe place is found.
*There’s no harm in sleeping in the Masjid if that would not lead to harm. (2)
Footnote a: There is a difference of opinion regarding whether a woman on her menses is allowed in the Masjid. Visit link in which Shaikh Abu Khadeejah [may Allaah preserve him] has transmitted the opinion of Imaam Al-Albaanee [may Allaah have mercy upon him] on this subject matter, but take note that other scholars hold a different position. https://abukhadeejah.com/menstruating-women-can-visit-the-masjid-recite-the-quran-read-from-the-mushaf/
[Ref 1: Fat-hul Baaree Sharh Saheeh Al-Bukhaaree Vol 1. Page 692. Daarus Salaam. 1st Edition 1421AH (Year 2000)]
[Ref 2: Al-Hulalul Ibreeziyyah Min At-Ta’leeqaat Al-Baaziyyah Alaah Saheeh Al-Bukhaaree 1/141-142]