Narrated Hakim bin Hizam:
I said to Allah's Messenger, "Before embracing Islam I used to do good deeds like giving in charity, slave-manumitting, and the keeping of good relations with Kith and kin. Shall I be rewarded for those deeds?" The Prophet (ﷺ) replied, "You became Muslim with all those good deeds (Without losing their reward)."
Narrated Hakim bin Hizam:
That he said, "O Allah's Messenger! What do you think about my good deeds which I used to do during the period of ignorance (before embracing Islam) like keeping good relations with my Kith and kin, manumitting of slaves and giving alms etc; Shall I receive the reward for that?" Allah's Messenger (ﷺ) said, "You have embraced Islam with all those good deeds which you did.
Narrated Ibn Mas`ud:
A man said, "O Allah's Messenger! Shall we be punished for what we did in the Prelslamic Period of ignorance?" The Prophet (ﷺ) said, "Whoever does good in Islam will not be punished for what he did in the Pre-lslamic Period of ignorance and whoever does evil in Islam will be punished for his former and later (bad deeds).
Hakim b. Hizam reported to 'Urwa b. Zubair that he said to the Messenger of Allah: Do you think that there is any thing for me (of he reward with the Lord) for the deed of religious purification that I did in the state of ignorance? Upon this he (the Messenger of Allah) said to him: You accepted Islam with all the previous virtues that you practised.