It is narrated from Abu Huraira and Zaid bin Khalid Al-Juhani (may Allah be pleased with them) that two men brought their dispute before the Messenger of Allah (ﷺ). One of them said: "O Messenger of Allah! Judge between us according to the Book of Allah." The other, who was more understanding of the two, said: "Yes, O Messenger of Allah (ﷺ)! Judge between us according to the Book of Allah, and allow me to speak regarding this matter." The Prophet (ﷺ) said: "Speak." The man said: "My son was working as a laborer with this man, and he committed adultery with his wife. I was told that my son would be stoned to death, so I gave him one hundred sheep and a slave girl as ransom for my son. Then I asked the people of knowledge, and they informed me that for my son the punishment is one hundred lashes and one year of exile, and the punishment of stoning is for his wife." Upon this, the Messenger of Allah (ﷺ) said: "By Him in Whose hand is my soul! I will judge between you according to the Book of Allah. Your sheep and your slave girl will be returned to you." Then he (ﷺ) had the son flogged with one hundred lashes and exiled for one year, and he ordered Anas Al-Aslami (may Allah be pleased with him) to go to the wife of the other man; if she confessed, she should be stoned. The woman confessed, and she was stoned.
Hadith Referenceمسند الإمام الشافعي / كتاب الحدود / 1574