We were with the Prophet ﷺ in a gathering when he said, "Pledge allegiance to me that you will not associate anything with Allah, that you will not steal, and that you will not commit fornication." He then recited this entire verse."Whoever among you fulfills this pledge, his reward is with Allah. Whoever commits any of these offenses and is punished for it in this world, that punishment is his expiation. And whoever commits any of these offenses and Allah conceals it for him, his matter rests with Allah. If He wills, He will forgive him, and if He wills, He will punish him."
كنا عند النبي ﷺ في مجلس فقال: بايعوني على أن لا تشركوا بالله شيئا ولا تسرقوا ولا تزنوا وقرأ هذه الآية كلها: فمن وفي منكم فأجره على الله، ومن أصاب من ذلك شيئا فعوقب به فهو كفارته، ومن أصاب من ذلك شيئا فستره الله عليه إن شاء غفر له وإن شاء عذبه.
Bukhari narrated it in the Book of Punishments (6784) and Muslim in the Book of Punishments (41:1709), both through Zuhri, from Abu Idris Khawlani, from Ubada bin Samit, as mentioned.It has also been narrated with a similar meaning from Ibn Khuzayma bin Thabit, from his father, from the Prophet ﷺ, who said, "Whoever commits a sin and has the punishment for that sin carried out against him, that is its atonement." However, this version is daif. It was narrated by Ahmad (21866), Daraqutni (3/214), Darimi (1236), Tabarani (4/101), and Hakim (4/388), all through the hadith of Usama bin Zayd Laythi, from Muhammad bin Munkadir, from Ibn Khuzayma bin Thabit, from his father, as mentioned.Tirmidhi said, "I asked Bukhari about this hadith, and he said, 'This is a hadith with confusion in it.'" Muhammad declared it severely daif, in Al-Ilal (2/602).As for Ibn Khuzayma bin Thabit, it is not known who he is. Some say he is Umara, others say Yazid, and others say something else. Moreover, there is disagreement over whether he is the son of Khuzayma bin Thabit or of Khuzayma bin Mamar Ansari. All of this weakens the hadith and renders it confused, as Bukhari said, though Ibn Hajar graded its chain hasan in Fath al-Bari (12/84), after attributing it to Ahmad through the hadith of Khuzayma bin Thabit, perhaps because of its corroborating narration.A note of caution, the intermediate link between Muhammad bin Munkadir and Khuzayma bin Thabit, namely "Ibn Khuzayma," has dropped out in some copies of Ahmad's Musnad. The correct position is to affirm its presence, as Ibn Hajar mentioned in Al-Atraf (2/311).