صحيح البخاري Sahih Bukhari كتاب الغسل The Book of Ghusl (Washing of the Whole Body)
بَابُ إِذَا ذَكَرَ فِي الْمَسْجِدِ أَنَّهُ جُنُبٌ يَخْرُجُ كَمَا هُوَ وَلاَ يَتَيَمَّمُ:

(17) Chapter. If someone while in the mosque remembers that he is Junub , he should leave (the mosque to take a bath) and should not perform Tayammum.

1 hadith
Hadith 275
حَدَّثَنَا عَبْدُ اللَّهِ بْنُ مُحَمَّدٍ ، قَالَ : حَدَّثَنَا عُثْمَانُ بْنُ عُمَرَ ، قَالَ : أَخْبَرَنَا يُونُسُ ، عَنِ الزُّهْرِيِّ ، عَنْ أَبِي سَلَمَةَ ، عَنْ أَبِي هُرَيْرَةَ ، قَالَ : " أُقِيمَتِ الصَّلَاةُ وَعُدِّلَتِ الصُّفُوفُ قياما ، فَخَرَجَ إِلَيْنَا رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ ، فَلَمَّا قَامَ فِي مُصَلَّاهُ ذَكَرَ أَنَّهُ جُنُبٌ ، فَقَالَ لَنَا : مَكَانَكُمْ ، ثُمَّ رَجَعَ فَاغْتَسَلَ ، ثُمَّ خَرَجَ إِلَيْنَا وَرَأْسُهُ يَقْطُرُ فَكَبَّرَ فَصَلَّيْنَا مَعَهُ " ، تَابَعَهُ عَبْدُ الْأَعْلَى ، عَنْ مَعْمَرٍ ، عَنْ الزُّهْرِيِّ ، وَرَوَاهُ الْأَوْزَاعِيُّ ، عَنْ الزُّهْرِيِّ .
Narrated Abu Huraira: Once the call (Iqama) for the prayer was announced and the rows were straightened. Allah's Apostle came out; and when he stood up at his Musalla, he remembered that he was Junub. Then he ordered us to stay at our places and went to take a bath and then returned with water dropping from his head. He said, "Allahu-Akbar", and we all offered the prayer with him.
Hadith Reference Sahih Bukhari / The Book of Ghusl (Washing of the Whole Body) / Hadith: 275
Hadith Grading محدثین: أحاديث صحيح البخاريّ كلّها صحيحة