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."
جاء رجل إلى النبي ﷺ فقال: يا رسول الله! أصبت حدا فأقمه علي، قال: وحضرت الصلاة، فصلى مع رسول الله ﷺ، فلما قضى الصلاة قال: يا رسول الله إني أصبت حدا فأقم في كتاب الله قال: هل حضرت معنا الصلاة؟ قال: نعم. قال: قد غفر لك.
Bukhari narrated it in the Book of Legal Punishments (6823), and Muslim in the Book of Repentance (2764), both through Amr bin Asim Kilabi, who said, Hammam bin Yahya narrated to us, who said, Ishaq bin Abdullah bin Abu Talha narrated to us, from Anas bin Malik, and he related it. The wording given is Muslim's, and in Bukhari's wording, "Allah has forgiven you your sin, or he said, your punishment."