وَعَنْ خُزَيْمَةَ بْنِ ثَابِتٍ قَالَ: قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ: «مَنْ أَصَابَ ذَنْبًا أُقِيمَ عَلَيْهِ حَدُّ ذَلِكَ الذَّنْبِ فَهُوَ كفارتُه» رَوَاهُ فِي شرح السّنة

Khuzaima b. Thabit reported God’s Messenger as saying, “If anyone commits a sin and has inflicted on him the prescribed punishment for that sin, it is an atonement for him.”

It is transmitted in Sharh as-sunna.