While we were in the mosque with the Messenger of Allah ﷺ, a Bedouin came in and began to urinate inside the mosque. The companions of the Messenger of Allah called out, "Stop! Stop!"The Messenger of Allah ﷺ said, "Do not interrupt him. Leave him alone."So they left him until he finished. Then the Messenger of Allah ﷺ called him over and said to him, "These mosques are not suitable for any of this urine or filth. They are only for the remembrance of Allah , prayer, and the recitation of the Quran," or words to that effect from the Messenger of Allah ﷺ.Then he ordered one of the men present to bring a bucket of water, which he poured over the spot.
بينما نحن في المسجد مع رسول الله ﷺ إذ جاء أعرابي، فقام يبول في المسجد، فقال أصحاب رسول الله: مه مه. قال: قال رسول الله ﷺ: لا تزرموه، دعوه فتركوه حتى بال، ثم إن رسول الله ﷺ دعاه، فقال له: إن هذه المساجد لا تصلح لشيء من هذا البول ولا القذر، إنما هي لذكر الله عز وجل والصلاة وقراءة القرآن أو كما قال رسول الله ﷺ قال: فأمر رجلا من القوم، فجاء بدلو من ماء، فشنه عليه.
Muslim narrated it in Kitab al-Tahara (285) from Zuhayr bin Harb, "Umar bin Yunus Hanafi narrated to us, Ikrima bin Ammar narrated to us, Ishaq bin Abu Talha narrated to us, Anas bin Malik, who is Ishaq's uncle, narrated to me," and he said, then he related it.Bukhari narrated it in Kitab al-Wudu (219) through another route from Ishaq, similarly, in a shortened form.As for His saying, "He is glorified therein in the mornings and the evenings, by men..." [Nur 24:36–37], this indicates that men are the ones who frequent the masjids, while for a woman, praying in her own house is better for her than praying in the masjid, as stated in the hadith.