Abdullah bin Abbas reported,

I heard Umar bin Khattab say, "When Abdullah bin Ubayy died, the Messenger of Allah ﷺ was called upon to pray over him. He rose and went to him, and when he stood over him intending to pray, I moved until I stood facing his chest and said, 'Messenger of Allah, will you pray over the enemy of Allah, Abdullah bin Ubayy, the one who said on such and such a day such and such a thing?' I was listing his offenses one by one, while the Messenger of Allah ﷺ was smiling.When I had said too much, he said, 'Step back from me, Umar. I have been given a choice and I have made my choice. It has been said to me, "Ask forgiveness for them or do not ask forgiveness for them. Even if you ask forgiveness for them seventy times, Allah will not forgive them" [Tawbah 9:80]. If I knew that by exceeding seventy he would be forgiven, I would exceed it.'Then he prayed over him and walked with him, standing at his grave until the burial was completed. I was amazed at myself and at my boldness toward the Messenger of Allah ﷺ, though Allah and His Messenger know best. By Allah, only a short time passed before these two verses were revealed, "And do not pray over any of them who has died, ever, nor stand at his grave" [Tawbah 9:84], to the end of the verse. After that, the Messenger of Allah ﷺ never prayed over a hypocrite nor stood at his grave until Allah took him."

Tirmidhi 3097

Sahih

حدثنا عبد بن حميد حدثنا يعقوب بن إبراهيم بن سعد عن أبيه عن محمد بن إسحق عن الزهري عن عبيد الله بن عبد الله بن عتبة

عن ابن عباس قال

سمعت عمر بن الخطاب يقول لما توفي عبد الله بن أبي دعي رسول الله ﷺ للصلاة عليه فقام إليه فلما وقف عليه يريد الصلاة تحولت حتى قمت في صدره فقلت يا رسول الله أعلى عدو الله عبد الله بن أبي القائل يوم كذا وكذا كذا وكذا يعد أيامه قال ورسول الله ﷺ يتبسم حتى إذا أكثرت عليه قال أخر عني يا عمر إني خيرت فاخترت قد قيل لي {استغفر لهم أو لا تستغفر لهم إن تستغفر لهم سبعين مرة فلن يغفر الله لهم} لو أعلم أني لو زدت على السبعين غفر له لزدت قال ثم صلى عليه ومشى معه فقام على قبره حتى فرغ منه قال فعجب لي وجرأتي على رسول الله ﷺ والله ورسوله أعلم فوالله ما كان إلا يسيرا حتى نزلت هاتان الآيتان {ولا تصل على أحد منهم مات أبدا ولا تقم على قبره} إلى آخر الآية قال فما صلى رسول الله ﷺ بعده على منافق ولا قام على قبره حتى قبضه الله

الترمذي 3097صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Tafsir of the Quran
Chapter
From Surah Tawbah
Numbering
Darussalam 3097
Tirmidhi 3097