كتاب الشروط
Chapter: The conditions not permissible in legal punishments
باب الشُّرُوطِ الَّتِي لاَ تَحِلُّ فِي الْحُدُودِ
Sahih al-Bukhari 2724, 2725

Narrated Abu Huraira and Zaid bin Khalid Al-Juhani:

A bedouin came to Allah's Messenger (ﷺ) and said, "O Allah's apostle! I ask you by Allah to judge My case according to Allah's Laws." His opponent, who was more learned than he, said, "Yes, judge between us according to Allah's Laws, and allow me to speak." Allah's Messenger (ﷺ) said, "Speak." He (i .e. the bedouin or the other man) said, "My son was working as a laborer for this (man) and he committed illegal sexual intercourse with his wife. The people told me that it was obligatory that my son should be stoned to death, so in lieu of that I ransomed my son by paying one hundred sheep and a slave girl. Then I asked the religious scholars about it, and they informed me that my son must be lashed one hundred lashes, and be exiled for one year, and the wife of this (man) must be stoned to death." Allah's Messenger (ﷺ) said, "By Him in Whose Hands my soul is, I will judge between you according to Allah's Laws. The slave-girl and the sheep are to be returned to you, your son is to receive a hundred lashes and be exiled for one year. You, Unais, go to the wife of this (man) and if she confesses her guilt, stone her to death." Unais went to that woman next morning and she confessed. Allah's Messenger (ﷺ) ordered that she be stoned to death.

حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا لَيْثٌ، عَنِ ابْنِ شِهَابٍ، عَنْ عُبَيْدِ اللَّهِ بْنِ عَبْدِ اللَّهِ بْنِ عُتْبَةَ بْنِ مَسْعُودٍ، عَنْ أَبِي هُرَيْرَةَ، وَزَيْدِ بْنِ خَالِدٍ الْجُهَنِيِّ، رضى الله عنهم أَنَّهُمَا قَالاَ إِنَّ رَجُلاً مِنَ الأَعْرَابِ أَتَى رَسُولَ اللَّهِ صلى الله عليه وسلم فَقَالَ رَسُولَ اللَّهِ أَنْشُدُكَ اللَّهَ إِلاَّ قَضَيْتَ لِي بِكِتَابِ اللَّهِ‏.‏ فَقَالَ الْخَصْمُ الآخَرُ وَهْوَ أَفْقَهُ مِنْهُ نَعَمْ فَاقْضِ بَيْنَنَا بِكِتَابِ اللَّهِ، وَائْذَنْ لِي‏.‏ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ قُلْ ‏"‏‏.‏ قَالَ إِنَّ ابْنِي كَانَ عَسِيفًا عَلَى هَذَا، فَزَنَى بِامْرَأَتِهِ، وَإِنِّي أُخْبِرْتُ أَنَّ عَلَى ابْنِي الرَّجْمَ، فَافْتَدَيْتُ مِنْهُ بِمِائَةِ شَاةٍ وَوَلِيدَةٍ، فَسَأَلْتُ أَهْلَ الْعِلْمِ فَأَخْبَرُونِي أَنَّمَا عَلَى ابْنِي جَلْدُ مِائَةٍ، وَتَغْرِيبُ عَامٍ، وَأَنَّ عَلَى امْرَأَةِ هَذَا الرَّجْمَ‏.‏ فَقَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏"‏ وَالَّذِي نَفْسِي بِيَدِهِ لأَقْضِيَنَّ بَيْنَكُمَا بِكِتَابِ اللَّهِ، الْوَلِيدَةُ وَالْغَنَمُ رَدٌّ، وَعَلَى ابْنِكَ جَلْدُ مِائَةٍ وَتَغْرِيبُ عَامٍ، اغْدُ يَا أُنَيْسُ إِلَى امْرَأَةِ هَذَا فَإِنِ اعْتَرَفَتْ فَارْجُمْهَا ‏"‏‏.‏ قَالَ فَغَدَا عَلَيْهَا فَاعْتَرَفَتْ، فَأَمَرَ بِهَا رَسُولُ اللَّهِ صلى الله عليه وسلم فَرُجِمَتْ‏.‏
Reference : Sahih al-Bukhari 2724, 2725
In-book reference : Book 54, Hadith 13
USC-MSA web (English) reference : Vol. 3, Book 50, Hadith 885
  (deprecated numbering scheme)