Sunan Ibn Majah, Book 1, Hadith 572 (In-Book) ⓘ
It was narrated that Abu Hurairah said: "A Bedouin entered the mosque when the Messenger of Allah was sitting there, and (the man) said: 'O Allah, forgive me and Muhammed, and do not forgive anyone else with us.' The Messenger of Allah smiled and said: 'You have placed restrictions on something that is vast.' Then the Bedouin turned away, went to a corner of the mosque, spread his legs and began to urinate. After he had a better understanding, the Bedouin said: 'He got up and came to me, and may my father and mother be ransomed for him, he did not rebuke me nor revile me. He said: "This mosque is not for urinating in. Rather it is built for the remembrance of Allah and prayer.'" Then he called for a large vessel of water and poured it over the place where he had urinated."
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا عَلِيُّ بْنُ مُسْهِرٍ، عَنْ مُحَمَّدِ بْنِ عَمْرٍو، عَنْ أَبِي سَلَمَةَ، عَنْ أَبِي هُرَيْرَةَ، قَالَ دَخَلَ أَعْرَابِيٌّ الْمَسْجِدَ وَرَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ جَالِسٌ فَقَالَ اللَّهُمَّ اغْفِرْ لِي وَلِمُحَمَّدٍ وَلاَ تَغْفِرْ لأَحَدٍ مَعَنَا . فَضَحِكَ رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ وَقَالَ " لَقَدِ احْتَظَرْتَ وَاسِعًا " . ثُمَّ وَلَّى حَتَّى إِذَا كَانَ فِي نَاحِيَةِ الْمَسْجِدِ فَشَجَ يَبُولُ . فَقَالَ الأَعْرَابِيُّ بَعْدَ أَنْ فَقِهَ فَقَامَ إِلَىَّ بِأَبِي وَأُمِّي . فَلَمْ يُؤَنِّبْ وَلَمْ يَسُبَّ . فَقَالَ " إِنَّ هَذَا الْمَسْجِدَ لاَ يُبَالُ فِيهِ وَإِنَّمَا بُنِيَ لِذِكْرِ اللَّهِ وَلِلصَّلاَةِ " . ثُمَّ أَمَرَ بِسَجْلٍ مِنَ مَاءٍ فَأُفْرِغَ عَلَى بَوْلِهِ .
also referenced under: Hadith 529 (Reference) & Volume 1, Book 1, Hadith 529 (DarusSalam)