to soil the mosque or not; and this is the position of the majority of scholars.
2 – It is likewise forbidden for a person in janābah to remain in the mosque. As for merely passing through it, whether the person is junub or menstruating, most scholars permit this, citing Allah’s words: “And do not come near the prayer… nor while you are in a state of janābah—unless you are simply passing along the way—until you have washed yourselves” (Q 4:43). The meaning is: avoid the places of prayer, namely the mosques, while you are junub, except for someone whose route leads through them.
3 – Regarding his statement, “I do not permit the mosque”: a mosque is a concrete entity, not an abstract notion. Therefore the prohibition conveyed by the Prophet’s wording cannot be directed at the entity itself, but rather at the use of it—staying there, sleeping there, and the like. Allah likewise says, “Your mothers are forbidden to you” (Q 4:23); the intent is not the mothers as persons, but marrying them.
4 – Al-Mughnī states: It is permissible to pass through the mosque for some need—such as picking something up, leaving something there, or because the pathway lies through it. This is the view of Mālik and al-Shāfiʿī, and the dispensation is also reported from Ibn Masʿūd, Ibn ʿAbbās, Ibn al-Musayyib, Ibn Jubayr, and al-Ḥasan.
The proof for this allowance is the noble verse just cited, and the ḥadith in which the Prophet ﷺ said to ʿĀʾishah, “Hand me the small prayer-mat from the mosque.” She replied, “But I am menstruating.” He said, “Your menstruation is not in your hand.” Reported by Muslim (298).
Jābir said, “One of us would pass through the mosque in a state of janābah, merely crossing it.” Reported by Saʿīd ibn Manṣūr (645).
ʿAṭāʾ ibn Yasār said, “A man from among the Companions of the Messenger of Allah ﷺ would be junub; he would perform ablution, then enter the mosque and sit there speaking with others.”