A man from Aslam came to the Prophet ﷺ while he was in the mosque and said that he had committed adultery. The Prophet ﷺ turned away from him, so the man moved to the side he had turned toward and testified against himself four times.The Prophet ﷺ then called him over and asked, "Are you insane? Are you married?"He replied, "Yes."So the Prophet ﷺ ordered that he be stoned at the prayer ground. When the stones struck him painfully, he ran off, until he was caught at al-Harrah and killed.
أن رجلا من أسلم، أتى النبي ﷺ وهو في المسجد فقال: إنه قد زنى، فأعرض عنه، فتنحى لشقه الذي أعرض، فشهد على نفسه أربع شهادات، فدعاه فقال: هل بك جنون؟ هل أحصنت؟ قال: نعم. فأمر به أن يرجم بالمصلى. فلما أذلقته الحجارة جمز، حتى أدرك بالحرة فقتل.
This was narrated by Bukhari in the Book of Divorce (5270) and Muslim in the Book of Prescribed Punishments (1691), both from the hadith of Ibn Shihab, who said, Abu Salama informed me, from Jabir, and he related it. Bukhari also narrated it in the Book of Prescribed Punishments (6820) from the hadith of Abdul-Razzaq, from Mamar, from Zuhri, from Abu Salama, from Jabir, with an addition, "The Prophet ﷺ said, 'Good,' and he prayed over him." He said, Yunus and Ibn Jurayj did not say, on the authority of Zuhri, "Then he prayed over him." Abu Abdullah (Bukhari) was asked about the statement "Then he prayed over him," whether it is correct or not. He said, Mamar narrated it. He was asked, Did anyone other than Mamar narrate it? He said, No. End of quote.I say, the hadith of Abdul-Razzaq is in his Musannaf (13337), and Muslim narrated it through his route, except that he did not give its wording in full but said it was similar to the narration of Aqeel, from Zuhri, from Saeed and Abu Salama, from Abu Hurairah. And in the hadith of Abu Hurairah there is no mention of the prayer. It was also narrated by Abu Dawud (4430), Tirmidhi (1429), Nasai (4/62–63), and others, all of whom said, "And he did not pray over him." So the mention of the prayer in Sahih Bukhari goes back to a discrepancy between the copies of the Musannaf of Abdul-Razzaq, and the correct position is that he did not pray over him, because a group of the narrators from Abdul-Razzaq did not mention the prayer over him, while Mahmud bin Ghaylan, from whom Bukhari narrated, differed from them and mentioned the prayer. See the names of this group in Fath al-Bari (12/130).As for what is narrated from Abu Umama bin Sahl bin Hunayf Ansari concerning the prayer over him, it is shadh and disconnected.His statement that the Prophet ﷺ prayed Dhuhr on the day Maiz was struck, and lengthened the first two units of the Dhuhr prayer until the people grew weary from the length of standing, then when he finished he ordered that he be stoned, and he was stoned. But he was not killed until Umar bin Khattab threw the jawbone of a camel at him, striking his head and killing him. Then a man said, when Maiz breathed his last, "May he perish!" It was said to the Prophet ﷺ, "O Messenger of Allah, will you pray over him?" He said, "No." Then the next day he prayed Dhuhr and lengthened the first two units as he had lengthened them the day before, or nearly so. When he finished, he said, "Pray over your companion." So the Prophet ﷺ and the people prayed over him.This was narrated by Abdul-Razzaq (13339), who said, Ibn Jurayj informed us, who said, Abdullah bin Abu Bakr informed me, who said, Ayub informed me, from Abu Umama bin Sahl bin Hunayf Ansari, and he related it. But it contains an anomaly in mentioning the prayer over Maiz, and the correct and established position is that he did not pray over him.Moreover, Abu Umama, whose name was Asad, had seen the Prophet but did not hear from him directly.The people of knowledge have differed regarding praying over one who has been subjected to a prescribed punishment. The majority of the people of knowledge held that praying over him is permissible. The Prophet ﷺ prayed over the Ghamidiyya woman and commanded the people to pray over her. However, it is permissible for the leader and for the people of knowledge and distinction to refrain from praying over one who has been punished, for various reasons, among them deterring people from sin. This differs from the case of those who wage war, for Abu Hanifa held that one should not pray over them, because they do not deserve to have mercy and forgiveness invoked for them, since they have warred against Allah and His Messenger.