Some people used to kill, and they did a great deal of it, and they used to commit adultery and they did a great deal of it, and they committed violations. They came to the Prophet [SAW] and said: "O Muhammad, what you say and call people to is good, if only you could tell us that there is any expiation for what we have done." Then Allah, the Mighty and Sublime, revealed: "And those who invoke not any other ilah (god) along with Allah up to for those, Allah will change their sins into good deeds," he said: "So Allah will change their Shirk into faith, and their adultery into chastity. And the Verse: "Say: O 'Ibadi (My slaves) who have transgressed against themselves (by committing evil deeds and sins)" was revealed. (Using translation from Nasāʾī 4003)
أَنَّ قَوْمًا كَانُوا قَتَلُوا فَأَكْثَرُوا وَزَنَوْا فَأَكْثَرُوا وَانْتَهَكُوا فَأَتَوُا النَّبِيَّ ﷺ فَقَالُوا يَا مُحَمَّدُ إِنَّ الَّذِي تَقُولُ وَتَدَعُو إِلَيْهِ لَحَقٌّ لَو تُخْبِرُنَا أَنَّ لِمَا عَمِلْنَاهُ كَفَّارَةً فَأَنْزَلَ اللهُ {وَالَّذِينَ لَا يَدْعُونَ مَعَ اللهِ إِلَهًا آخَرَ وَلَا يَقْتُلُونَ النَّفْسَ الَّتِي حَرَّمَ اللهُ إِلَّا بِالْحَقِّ وَلَا يَزْنُونَ} [الفرقان 68] إِلَى {فَأُولَئِكَ يُبَدِّلُ اللهُ سَيِّئَاتِهِمْ حَسَنَاتٍ وَكَانَ اللهُ غَفُورًا رَحِيمًا} [الفرقان 70] قَالَ يُبَدَّلُ اللهُ بِشِرْكِهِمْ إِيمَانًا وَبِزِنَاهُمْ إِحْصَانًا وَنَزَلَتْ {قُلْ يَا عَبَّادِيَ الَّذِينَ أَسْرَفُوا عَلَى أَنْفُسِهِمْ} [الزمر 53] الْآيَةَ