Bara bin Azib reported,

A Jew who had been blackened with soot and flogged was brought past the Prophet ﷺ, so he called the Jews over and asked, "Is this what you find in your Book as the penalty for adultery?"They said, "Yes."Then he summoned one of their scholars and said, "I adjure you by Allah, who sent down the Torah to Musa, is this what you find in your Book as the penalty for adultery?"The man replied, "No. And had you not put me under this oath, I would not have told you. What we find in it is stoning. But adultery became widespread among our nobility, so whenever we caught a noble we let him go, and whenever we caught a weak man we carried out the penalty on him. So we said, come, let us agree on something we can apply to noble and lowly alike, and we substituted blackening the face and flogging in place of stoning."The Messenger of Allah ﷺ then said, "Allah, I am the first to revive Your command when they had killed it." He gave the order and the man was stoned.Then Allah عز وجل revealed, "Messenger, do not let those who race toward disbelief grieve you," down to His words, "If you are given this, take it" [Maidah 5:41]. That is, they were saying, go to Muhammad ﷺ, and if he instructs you with blackening and flogging, accept it, but if he gives you a ruling of stoning, then beware. So Allah Most High revealed, "And whoever does not judge by what Allah has sent down, those are the disbelievers" [Maidah 5:44], "And whoever does not judge by what Allah has sent down, those are the wrongdoers" [Maidah 5:45], and "And whoever does not judge by what Allah has sent down, those are the rebellious" [Maidah 5:47]. All of these verses were revealed concerning the disbelievers.Another narration goes as far as the words, "The Prophet ﷺ gave the order and the man was stoned," without mentioning what follows about the revelation of the verse.

Muslim 4441

Sahih

حدثنا ابن نمير وأبو سعيد الأشج قالا حدثنا وكيع حدثنا الأعمش بهذا الإسناد نحوه إلى قوله فأمر به النبي ﷺ فرجم ولم يذكر ما بعده من نزول الآية

مسلم 4441صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Legal punishments
Chapter
Stoning of Jews, the people of dhimma, for adultery
Numbering
Darussalam 4441
Muslim 4441