Umar bin Khattab reported,

When Abdullah bin Ubayy bin Salul died, the Messenger of Allah ﷺ was called to pray over him. As the Messenger of Allah ﷺ rose, I sprang up to him and said, "Messenger of Allah, are you going to pray over Ibn Ubayy, when he said such and such on such and such a day?" I went on listing his statements to him.The Messenger of Allah ﷺ smiled and said, "Step aside, Umar."When I persisted with him, he said, "I was given a choice, and I chose. If I knew that going beyond seventy times would bring him forgiveness, I would go beyond it."So the Messenger of Allah ﷺ prayed over him and then left. Only a short while passed before the two verses of Baraah were revealed, "And never pray over any of them who dies, nor stand at his grave. They disbelieved in Allah and His Messenger and died as rebellious sinners" [Tawbah 9:84].Umar said, "Afterward I was amazed at my own boldness toward the Messenger of Allah ﷺ that day. Allah and His Messenger know best."

Bukhari 1366

Sahih

حدثنا يحيى بن بكير حدثني الليث عن عقيل عن ابن شهاب عن عبيد الله بن عبد الله عن ابن عباس

عن عمر بن الخطاب رضي الله عنهم أنه قال

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

البخاري 1366صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Funerals
Chapter
What is disliked of praying over the hypocrites and seeking forgiveness for the polytheists
Numbering
Darussalam 1366
Bukhari 1366