“These mosques have been erected solely for the remembrance of Allah, for prayer, and for the recitation of the Quran,” or words to that effect, he said. The Prophet ﷺ then told one of the men present to bring a bucket of water, and he sprinkled it over the spot.
This is Muslim’s version, which does not include the additional phrase “and relieving oneself”; that wording appears only in the transmission of Aḥmad and, in one of its routes, al-Bayhaqī.
A corroborating report comes from Abū Hurayrah, who said:
“A Bedouin entered the mosque while the Messenger of Allah ﷺ was sitting there and said, ‘O Allah, forgive me and Muhammad, and do not forgive anyone else who is with us.’ The Messenger of Allah ﷺ laughed and remarked, ‘You have asked for something vast to be restricted.’ The man then turned away, and when he reached a corner of the mosque he began to urinate. The Messenger of Allah ﷺ stood up to him and said, ‘This House has been built only for the remembrance of Allah and for prayer; one must not urinate in it.’ He then called for a bucket of water and poured it over the place.
“After the Bedouin had grasped the lesson he used to say, ‘The Prophet ﷺ—may my father and mother be sacrificed for him—stood over me, yet he neither cursed me, nor rebuked me, nor struck me.’”
Ibn Mājah and Aḥmad recorded this through the chain of Muḥammad ibn ʿAmr, from Abū Salamah, from Abū Hurayrah; its isnād is good. Ibn Ḥibbān also narrated it, as cited in Fatḥ al-Bārī.
The abridged versions reported by Anas and Abū Hurayrah appear in both Ṣaḥīḥ al-Bukhārī and Ṣaḥīḥ Muslim, among other collections, but they omit the wording that constitutes the key proof here, which we have already presented.