He came to the Prophet ﷺ when his father died and said, "Give me your shirt so I may shroud him in it, pray over him, and seek forgiveness for him." So he gave him his shirt and said, "When you have finished, inform me."When he intended to pray over him, Umar pulled him back and said, "Has Allah not forbidden you to pray over the hypocrites?"He replied, "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]." So he prayed over him.Then Allah revealed, "And never pray over any of them who has died, nor stand at his grave" [Tawbah 9:84]. So he ceased praying over them.
حدثنا محمد بن بشار حدثنا يحيى بن سعيد حدثنا عبيد الله أخبرنا نافع عن ابن عمر قال جاء
إلى النبي ﷺ حين مات أبوه فقال أعطني قميصك أكفنه فيه وصل عليه واستغفر له فأعطاه قميصه وقال إذا فرغتم فآذنوني فلما أراد أن يصلي جذبه عمر وقال أليس قد نهى الله أن تصلي على المنافقين فقال أنا بين خيرتين {استغفر لهم أو لا تستغفر لهم} فصلى عليه فأنزل الله {ولا تصل على أحد منهم مات أبدا ولا تقم على قبره} فترك الصلاة عليهم
Agreed upon [by Bukhari and Muslim]. Bukhari narrated it in the Book of Dress, chapter on wearing the shirt, no. 5796, and Muslim, no. 2774, from the hadith of Yahya Qattan, through this same chain.