When Abdullah bin Ubayy died, his son came to the Prophet ﷺ and said, "Messenger of Allah, give me your shirt so I may shroud him in it."The Messenger of Allah ﷺ said, "Inform me when he is ready."When the Prophet ﷺ intended to pray over him, Umar bin Khattab said to him, "Is that something you should do?"The Prophet ﷺ prayed over him anyway and said, "I have been given a choice between two options, 'Whether you seek forgiveness for them or do not seek forgiveness for them' [Tawbah 9:80]."Then Allah revealed, "And never pray over any of them who dies, nor stand at his grave" [Tawbah 9:84].
حدثنا أبو بشر بكر بن خلف حدثنا يحيى بن سعيد عن عبيد الله عن نافع
لما توفي عبد الله بن أبي جاء ابنه إلى النبي ﷺ فقال يا رسول الله أعطني قميصك أكفنه فيه فقال رسول الله ﷺ آذنوني به فلما أراد النبي ﷺ أن يصلي عليه قال له عمر بن الخطاب ما ذاك لك فصلى عليه النبي ﷺ فقال له النبي ﷺ أنا بين خيرتين {استغفر لهم أو لا تستغفر لهم} فأنزل الله عز وجل {ولا تصل على أحد منهم مات أبدا ولا تقم على قبره}
Bukhari narrated it in the Book of Funerals, Chapter on Shrouding in a Shirt Whether Hemmed or Not, no. 1269, from the hadith of Yahya bin Saeed with this wording, and others, and Muslim in the Characteristics of the Hypocrites, Chapter on the Characteristics of the Hypocrites and Their Rulings, no. 2774, from the hadith of Ubaydullah bin Umar with this wording.