The Messenger of Allah ﷺ said, "When a servant accepts Islam and his Islam is sincere, Allah records for him every good deed he had previously done, and every bad deed he had previously committed is wiped away. After that, the reckoning begins. A good deed is rewarded tenfold up to seven hundred times, and a bad deed is recorded as one, unless Allah overlooks it."
قال رسول الله ﷺ: إذا أسلم العبد فحسن إسلامه، كتب الله له كل حسنة كان أزلفها، ومحيت عنه كل سيئة كان أزلفها، ثم كان بعد ذلك القصاص. الحسنة بعشرة أمثالها إلى سبعمائة ضعف، والسيئة بمثلها إلا أن يتجاوز الله عز وجل عنها.
Nasai (4998) narrated it from Ahmad bin Mualla bin Yazid, who said, Safwan bin Salih told us, who said, Walid told us, who said, Malik told us, from Zayd bin Aslam, from Ata bin Yasar, from Abu Saeed Khudri, mentioning the same. Bukhari mentioned it in the Book of Iman (41) as a suspended report from Malik, and did not provide a full chain for it anywhere else, except that he omitted the phrase "Allah recorded for him every good deed he had put forward beforehand," because it poses a problem according to established principles, since a disbeliever is not rewarded for righteous deeds performed while in his disbelief and polytheism, for one of the conditions for seeking closeness to Allah is that the person must know the One to whom he is drawing near, and the disbeliever does not meet that condition. Maziri and others mentioned this, and Qadi Iyad followed him in affirming this difficulty.Nawawi rejected this, saying, The correct view held by the careful scholars, and some of them even reported a consensus on it, is that if a disbeliever performs beautiful deeds such as giving charity and maintaining family ties, and then becomes Muslim and dies as a Muslim, the reward for those deeds is recorded for him. As for the claim that this contradicts established principles, it is not accepted, for some deeds of a disbeliever are indeed taken into account in worldly matters, such as the atonement for zihar, since he is not required to repeat it if he becomes Muslim, and it suffices for him. See Fath al-Bari (1/99).His word "azlafaha" means he had advanced it and put it forward beforehand.