Anas bin Malik reported,

A man came to the Prophet ﷺ and said, "Messenger of Allah, I have committed an offense that requires a prescribed punishment, so carry it out on me."The time for prayer arrived, and he prayed with the Messenger of Allah ﷺ. When the prayer was finished, he said, "Messenger of Allah, I have committed an offense that requires a prescribed punishment, so apply to me what is in the Book of Allah."The Prophet ﷺ asked, "Did you pray with us just now?"The man replied, "Yes."He said, "You have been forgiven."

Azami 1748

Sahih

عن أنس بن مالك قال

جاء رجل إلى النبي ﷺ فقال: يا رسول الله! أصبت حدا فأقمه علي، قال: وحضرت الصلاة، فصلى مع رسول الله ﷺ، فلما قضى الصلاة قال: يا رسول الله إني أصبت حدا فأقم في كتاب الله قال: هل حضرت معنا الصلاة؟ قال: نعم. قال: قد غفر لك.

الأعظمي 1748صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Prayer
Chapter
Obligation of prayer and its virtue
Section
Prayer is an expiation
Numbering
Jami al-Kamil 1748 (2nd edition)
Azami 1748