إِلَّا مَن تَابَ وَآمَنَ وَعَمِلَ عَمَلًا صَالِحًا فَأُولَٰئِكَ يُبَدِّلُ اللَّهُ سَيِّئَاتِهِمْ حَسَنَاتٍ ۗ وَكَانَ اللَّهُ غَفُورًا رَّحِيمًا
“Except for those who repent, believe, and do righteous work. For them, Allāh will replace their evil deeds with good. And ever is Allāh Forgiving and Merciful.”
Al-Ḥāfiẓ Ibn Rajab [d. 795 AH] comments:
As for the claim [that this verse proves that] one who has amassed numerous misdeeds is better than who has not, we reply:
The replacement [of evil deeds] only applies to one who feels regret for the sins he engaged in, to the point where his [evil deeds] completely monopolise his attention.
Everytime he remembers [his sin], he feels a greater and more intense fear, trepidation, apprehensiveness, and shyness before Allāh. Thus, he feels an immediate and urgent drive towards engaging in expiative acts of righteousness as Allāh says [in this verse]:
إِلَّا مَن تَابَ وَآمَنَ وَعَمِلَ عَمَلًا صَالِحًا
‘Except for those who repent, believe and do righteous work…’
Whomever finds himself in such a condition experiences the painful bitterness of regret and sorrow for his misdeeds that have transpired. This pain is greater by far even than the sweetness he originally felt when he engaged in those sins. Hence, every sin from his many transgressions becomes a means towards engagement in acts of righteousness that erase [what came before it]. It should then come as no surprise the replacement of these sins with good deeds [as in the verse]. There is also many authentic aḥādīth that explicitly prove that any disbeliever who enters into Islām, and makes excellent his Islām, will have all his misdeeds that he previously engaged in—while in the state of associating partners with Allāh—replaced with good deeds.
Source: Jāmiʿ al-ʿUlūm: 322
Translated by: Riyāḍ al-Kanadī