كتاب الصيام
13  
The Book of Fasting
(13)
Chapter: The fasting is valid for the one who is Junub when dawn comes
(13)
باب صِحَّةِ صَوْمِ مَنْ طَلَعَ عَلَيْهِ الْفَجْرُ وَهُوَ جُنُبٌ ‏‏
Sahih Muslim 1110

'A'isha reported that a person came to the Apottle of Allah (ﷺ) asking for a fatwa (religious verdict). She ('A'isha) had been overhearing it from behind the curtain. 'A'isha added that he (the person) had said:

Messenger of Allah, (the time) of prayer overtakes me as I am in a state of junub; should I observe fast (in this state)? Upon this the Messenger of Allah (ﷺ) said: (At times the time) of prayer overtakes me while I am in a state of junub, and I observe fast (in that very state), whereupon he said: Messenger of Allah, you are not like us Allah has pardoned all your sins, the previous ones and the later ones. Upon this he (the Holy Prophet) said: By Allah, I hope I am the most God-fearirg of you, and possess the best knowledge among you of those (things) against which I should guard.
حَدَّثَنَا يَحْيَى بْنُ أَيُّوبَ، وَقُتَيْبَةُ، وَابْنُ، حُجْرٍ قَالَ ابْنُ أَيُّوبَ حَدَّثَنَا إِسْمَاعِيلُ بْنُ، جَعْفَرٍ أَخْبَرَنِي عَبْدُ اللَّهِ بْنُ عَبْدِ الرَّحْمَنِ، - وَهُوَ ابْنُ مَعْمَرِ بْنِ حَزْمٍ الأَنْصَارِيُّ أَبُو طُوَالَةَ - أَنَّ أَبَا يُونُسَ، مَوْلَى عَائِشَةَ أَخْبَرَهُ عَنْ عَائِشَةَ، - رضى الله عنها - أَنَّ رَجُلاً، جَاءَ إِلَى النَّبِيِّ صلى الله عليه وسلم يَسْتَفْتِيهِ وَهِيَ تَسْمَعُ مِنْ وَرَاءِ الْبَابِ فَقَالَ يَا رَسُولَ اللَّهِ تُدْرِكُنِي الصَّلاَةُ وَأَنَا جُنُبٌ أَفَأَصُومُ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ وَأَنَا تُدْرِكُنِي الصَّلاَةُ وَأَنَا جُنُبٌ فَأَصُومُ ‏"‏ ‏.‏ فَقَالَ لَسْتَ مِثْلَنَا يَا رَسُولَ اللَّهِ قَدْ غَفَرَ اللَّهُ لَكَ مَا تَقَدَّمَ مِنْ ذَنْبِكَ وَمَا تَأَخَّرَ ‏.‏ فَقَالَ ‏"‏ وَاللَّهِ إِنِّي لأَرْجُو أَنْ أَكُونَ أَخْشَاكُمْ لِلَّهِ وَأَعْلَمَكُمْ بِمَا أَتَّقِي ‏"‏ ‏.‏
Reference : Sahih Muslim 1110
In-book reference : Book 13, Hadith 99
USC-MSA web (English) reference : Book 6, Hadith 2455
  (deprecated numbering scheme)