All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Allah, The Exalted, Says (what means): {Except for those who repent, believe and do righteous work. For them Allah will replace their evil deeds with good deeds} [Quran 25:70] There are two opinions regarding the meaning of the verse, and neither of them is problematic. According to the first opinion, the verse means that Allah, The Exalted, guides them to do righteous deeds to replace the evil deeds they had committed. Replacing the evil deeds with good ones in this sense means that they substitute their past sinful actions with good ones. The second opinion is that their very sins are turned into good deeds on account of their sincere repentance and of quitting the sins. This is because whenever they recall their past sins, they regret committing them and such regret is added to their record of good deeds, replacing the sins they had committed. Ibn Katheer said what is summarized as follows: “Allah, The Exalted, Says (what means): {For them Allah will replace their evil deeds with good. And ever is Allah Forgiving and Merciful.} [Quran 25:70] There are two opinions regarding the meaning of the verse: {Allah will replace their evil deeds with good}; the first is that these people are guided to do good deeds to replace the sins they had committed. ‘Ali ibn Abu Talhah narrated that Ibn ‘Abbaas said regarding this verse: ‘It refers to the believers who had committed sins prior to their belief. Allah, The Exalted, did not approve that for them and, therefore, guided them to do good deeds instead, thus replacing their sins with good deeds’ … This means that their situations changed (from committing sins to performing righteous deeds). ‘Ataa’ ibn Abu Rabaah said: ‘This occurs in the worldly life; a man may have a bad conduct and then Allah, The Exalted, replaces it with a good one.’ Sa‘eed ibn Jubayr said: ‘Allah, The Exalted, replaced their idol worship with His worship, their fighting against Muslims with fighting against the polytheists, and their marriage to polytheistic women with marriage to believing women.’ Al-Hasan Al-Basri said: ‘Allah, The Exalted, replaced their evil deeds with good ones, their polytheism with worshiping Allah alone, their immorality with chastity, and their disbelief with belief (in Islam). This opinion is the one adopted by Abu Al-‘Aaliyah, Qataadah, and others.’ The second opinion holds that these past sins are turned into good deeds by virtue of sincere repentance. This happens because whenever a repentant person recalls his past sins, he regrets committing them, recites the Istirjaa’ Thikr (saying “Indeed we belong to Allah, and indeed to Him we shall return”), and seeks forgiveness. Accordingly, such sins are turned into acts of obedience in this sense.” [End of Quote]
Allah knows best.