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.
أَنَّ قَوْمًا كَانُوا قَتَلُوا فَأَكْثَرُوا وَزَنَوْا فَأَكْثَرُوا وَانْتَهَكُوا فَأَتَوُا النَّبِيَّ ﷺ قَالُوا يَا مُحَمَّدُ إِنَّ الَّذِي تَقُولُ وَتَدْعُو إِلَيْهِ لَحَسَنٌ لَوْ تُخْبِرُنَا أَنَّ لِمَا عَمِلْنَا كَفَّارَةً فَأَنْزَلَ اللَّهُ ﷻ { وَالَّذِينَ لاَ يَدْعُونَ مَعَ اللَّهِ إِلَهًا آخَرَ } إِلَى { فَأُولَئِكَ يُبَدِّلُ اللَّهُ سَيِّئَاتِهِمْ حَسَنَاتٍ } قَالَ يُبَدِّلُ اللَّهُ شِرْكَهُمْ إِيمَانًا وَزِنَاهُمْ إِحْصَانًا وَنَزَلَتْ { قُلْ يَا عِبَادِيَ الَّذِينَ أَسْرَفُوا عَلَى أَنْفُسِهِمْ } الآيَةَ