We were with the Messenger of Allah ﷺ in a gathering when he said, "Pledge allegiance to me that you will not associate anything with Allah, that you will not commit fornication, that you will not steal, and that you will not kill any soul whom Allah has forbidden except by right. Whoever among you fulfills this, his reward is with Allah. Whoever commits any of these offenses and is punished for it, that punishment is an expiation for him. And whoever commits any of these offenses and Allah conceals it for him, his affair rests with Allah. If He wills, He will pardon him, and if He wills, He will punish him."
كنا مع رسول الله ﷺ في مجلس، فقال: تبايعوني على أن لا تشركوا بالله شيئا، ولا تزنوا، ولا تسرقوا، ولا تقتلوا النفس التي حرم الله إلا بالحق، فمن وفى منكم فأجره على الله، ومن أصاب شيئا من ذلك فعوقب به فهو كفارة له، ومن أصاب شيئا من ذلك فستره الله عليه، فأمره إلى الله إن شاء عفا عنه، وإن شاء عذبه.
Bukhari reported it in the Book of Tafsir (7894) and Muslim in the Book of Hudud (1709), both of them through Sufyan bin Uyayna, who said, Zuhri narrated to us, who said, Abu Idris narrated to me, who heard Ubada bin Samit say... and then he related it. The wording is Muslim's, and Bukhari's wording is similar.