Ubada bin Samit reported,

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."

Azami 6838

Sahih

عن عبادة بن الصامت قال

كنا عند النبي ﷺ في مجلس فقال: بايعوني على أن لا تشركوا بالله شيئا ولا تسرقوا ولا تزنوا وقرأ هذه الآية كلها: فمن وفي منكم فأجره على الله، ومن أصاب من ذلك شيئا فعوقب به فهو كفارته، ومن أصاب من ذلك شيئا فستره الله عليه إن شاء غفر له وإن شاء عذبه.

الأعظمي 6838صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Retaliation and crimes
Chapter
Retaliation
Section
Retribution and legal punishments are expiations for those who undergo them
Numbering
Jami al-Kamil 6838 (2nd edition)
Azami 6838