كتاب الإيمان
1  
The Book of Faith
(55)
Chapter: Clarifying the ruling of the action of an unbeliever if he accepts Islam after it
(55)
باب بَيَانِ حُكْمِ عَمَلِ الْكَافِرِ إِذَا أَسْلَمَ بَعْدَهُ ‏‏
Sahih Muslim 123 b

Hakim b. Hizam reported to 'Urwa b. Zubair that he said to the Messenger of Allah (ﷺ):

Messenger of Allah, do you think if there is any reward (of the Lord with me on the Day of Resurrection) for the deeds of religious purification that I performed in the state of ignorance, such as charity, freeing a slave, cementing of blood-relations? Upon this he (the Messenger of Allah) said to him: You have accepted Islam with all the previous virtues that you had practised.
وَحَدَّثَنَا حَسَنٌ الْحُلْوَانِيُّ، وَعَبْدُ بْنُ حُمَيْدٍ، - قَالَ الْحُلْوَانِيُّ حَدَّثَنَا وَقَالَ عَبْدٌ، حَدَّثَنِي - يَعْقُوبُ، - وَهُوَ ابْنُ إِبْرَاهِيمَ بْنِ سَعْدٍ - حَدَّثَنَا أَبِي، عَنْ صَالِحٍ، عَنِ ابْنِ شِهَابٍ، قَالَ أَخْبَرَنِي عُرْوَةُ بْنُ الزُّبَيْرِ، أَنَّ حَكِيمَ بْنَ حِزَامٍ، أَخْبَرَهُ أَنَّهُ، قَالَ لِرَسُولِ اللَّهِ صلى الله عليه وسلم أَىْ رَسُولَ اللَّهِ أَرَأَيْتَ أُمُورًا كُنْتُ أَتَحَنَّثُ بِهَا فِي الْجَاهِلِيَّةِ مِنْ صَدَقَةٍ أَوْ عَتَاقَةٍ أَوْ صِلَةِ رَحِمٍ أَفِيهَا أَجْرٌ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ أَسْلَمْتَ عَلَى مَا أَسْلَفْتَ مِنْ خَيْرٍ ‏"‏ ‏.‏
Reference : Sahih Muslim 123b
In-book reference : Book 1, Hadith 231
USC-MSA web (English) reference : Book 1, Hadith 223
  (deprecated numbering scheme)