When Abdullah bin Ubayy died, his son came to the Prophet ﷺ and said, "Messenger of Allah, give me your shirt so I may wrap him in it as a shroud, and pray over him, and ask forgiveness for him."The Prophet ﷺ gave him his shirt and said, "Let me know when it is time, and I will pray over him." So the son informed him.When he was about to pray over him, Umar pulled him back and said, "Has Allah not forbidden you to pray over the hypocrites?"The Prophet replied, "I am between two choices." Allah said, "Ask forgiveness for them or do not ask forgiveness for them. Even if you ask forgiveness for them seventy times, Allah will never forgive them" [Tawbah 9:80].So he prayed over him, and then this was revealed, "And never pray over any of them who has died" [Tawbah 9:84].
أن عبد الله بن أبي لما توفي جاء ابنه إلى النبي ﷺ فقال: يا رسول الله! أعطني قميصك أكفنه فيه، وصل عليه، واستغفر له، فأعطاه النبي ﷺ قميصه فقال: آذني أصلي عليه فآذنه: فلما أراد أن يصلي عليه جذبه عمر رضي الله عنه فقال: أليس الله قد نهاك أن تصلي على المنافقين؟ فقال: أنا بين خيرتين قال: {استغفر لهم أو لا تستغفر لهم إن تستغفر لهم سبعين مرة فلن يغفر الله لهم} [سورة التوبة: ٨٠] فصلي عليه، فنزلت: {ولا تصل على أحد منهم مات أبدا} [سورة التوبة: ٨٤].
Bukhari reported it in the chapter on funerals (1269), and Muslim in the chapter on the characteristics of the hypocrites (2774), both from the hadith of Yahya bin Saeed, from Ubaydullah bin Umar, from Nafi, from Ibn Umar, who mentioned it.Muslim said, and he added, "So he refrained from praying over them."