Sahih al-Bukhari, Hadith 4672

Narrated Ibn `Umar: When `Abdullah bin Ubai died, his son `Abdullah bin `Abdullah came to Allah's Messenger who gave his shirt to him and ordered him to shroud his father in it. Then he stood up to offer the funeral prayer for the deceased, but `Umar bin Al-Khattab took hold of his garment and said, "Do you offer the funeral prayer for him though he was a hypocrite and Allah has forbidden you to ask forgiveness for hypocrites?" The Prophet said, "Allah has given me the choice (or Allah has informed me) saying: "Whether you, O Muhammad, 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," (9.80) The he added, "I will (appeal to Allah for his sake) more than seventy times." So Allah's Messenger offered the funeral prayer for him and we too, offered the prayer along with him. Then Allah revealed: "And never, O Muhammad, pray (funeral prayer) for anyone of them that dies, nor stand at his grave. Certainly they disbelieved in Allah and His Apostle and died in a state of rebellion." (9.84)

حَدَّثَنِي إِبْرَاهِيمُ بْنُ الْمُنْذِرِ، حَدَّثَنَا أَنَسُ بْنُ عِيَاضٍ، عَنْ عُبَيْدِ اللَّهِ، عَنْ نَافِعٍ، عَنِ ابْنِ عُمَرَ ـ رضى الله عنهما ـ أَنَّهُ قَالَ لَمَّا تُوُفِّيَ عَبْدُ اللَّهِ بْنُ أُبَىٍّ جَاءَ ابْنُهُ عَبْدُ اللَّهِ بْنُ عَبْدِ اللَّهِ إِلَى رَسُولِ اللَّهِ صلى الله عليه وسلم فَأَعْطَاهُ قَمِيصَهُ وَأَمَرَهُ أَنْ يُكَفِّنَهُ فِيهِ ثُمَّ قَامَ يُصَلِّي عَلَيْهِ، فَأَخَذَ عُمَرُ بْنُ الْخَطَّابِ بِثَوْبِهِ فَقَالَ تُصَلِّي عَلَيْهِ وَهْوَ مُنَافِقٌ وَقَدْ نَهَاكَ اللَّهُ أَنْ تَسْتَغْفِرَ لَهُمْ‏.‏ قَالَ ‏"‏ إِنَّمَا خَيَّرَنِي اللَّهُ أَوْ أَخْبَرَنِي فَقَالَ ‏{‏اسْتَغْفِرْ لَهُمْ أَوْ لاَ تَسْتَغْفِرْ لَهُمْ إِنْ تَسْتَغْفِرْ لَهُمْ سَبْعِينَ مَرَّةً فَلَنْ يَغْفِرَ اللَّهُ لَهُمْ‏}‏ فَقَالَ سَأَزِيدُهُ عَلَى سَبْعِينَ ‏"‏‏.‏ قَالَ فَصَلَّى عَلَيْهِ رَسُولُ اللَّهِ صلى الله عليه وسلم وَصَلَّيْنَا مَعَهُ ثُمَّ أَنْزَلَ اللَّهُ عَلَيْهِ ‏{‏وَلاَ تُصَلِّ عَلَى أَحَدٍ مِنْهُمْ مَاتَ أَبَدًا وَلاَ تَقُمْ عَلَى قَبْرِهِ إِنَّهُمْ كَفَرُوا بِاللَّهِ وَرَسُولِهِ وَمَاتُوا وَهُمْ فَاسِقُونَ‏}‏

sunnah.com