I heard 'Umar bin al-Khattab say: When ‘Abdullah bin Ubayy died, the Messenger of Allah ﷺ was called to offer the funeral prayer for him, and when he stood by the deceased and was about to offer the prayer for him. I went and stood before him and said: O Messenger of Allah, (will you offer the funeral prayer) for the enemy of Allah who said such and such? and I listed what he had done. And the Messenger of Allah ﷺ was smiling until when I had said too much, he said: ʿMove away from me, O ‘Umar, for I was given the choice and I have chosen. It was said: ʿWhether you (O Muhammad) ask forgiveness for them (hypocrites) or ask not forgiveness for them- (and even) if you ask seventy times for their forgiveness-Allah will not forgive them' [at-Tawbah 9:80]. If I knew that by asking for forgiveness more than seventy times they would be forgiven, I would have done that.ʿ He said: Then he offered the funeral prayer for him, and walked with him (his bier), and stood by his grave until the burial was completed. He said: I was astounded that I had spoken so audaciously to the Messenger of Allah ﷺ; Allah and His Messenger know best. By Allah, it was not long before these two verses were revealed: “And never (O Muhammad pray (funeral prayer) for any of them (hypocrites) who dies, nor stand at his grave. Certainly they disbelieved in Allah and His Messenger, and died while they were Fasiqoon (rebellious, - disobedient to AIlah and His Messenger).ʿ[at-Tawbah9:84]. So after that the Messenger of Allah ﷺ did not offer the funeral prayer for any hypocrite or stand by his grave until he passed away.
قَالَسَمِعْتُ عُمَرَ بْنَ الْخَطَّابِ يَقُولُ لَمَّا تُوُفِّيَ عَبْدُ اللهِ بْنُ أُبَيٍّ دُعِيَ رَسُولُ اللهِ ﷺ لِلصَّلاةِ عَلَيْهِ فَقَامَ إِلَيْهِ فَلَمَّا وَقَفَ عَلَيْهِ يُرِيدُ الصَّلاةَتَحَوَّلْتُ حَتَّى قُمْتُ فِي صَدْرِهِ فَقُلْتُ يَا رَسُولَ اللهِ أَعَلَى عَدُوِّ اللهِ عَبْدِ اللهِ بْنِ أُبَيٍّ الْقَائِلِ يَوْمَ كَذَا وَكَذَا يُعَدِّدُ أَيَّامَهُ قَالَ وَرَسُولُ اللهِ ﷺ يَتَبَسَّمُ حَتَّى إِذَا أَكْثَرْتُ عَلَيْهِ قَالَ أَخِّرْ عَنِّي يَا عُمَرُ إِنِّي خُيِّرْتُ فَاخْتَرْتُ قَدْ قِيلَ {اسْتَغْفِرْ لَهُمْ أَوْ لَا تَسْتَغْفِرْ لَهُمْ إِنْ تَسْتَغْفِرْ لَهُمْ سَبْعِينَ مَرَّةً فَلَنْ يَغْفِرَ اللَّهُ لَهُمْ} [التوبة 80] لَوْ أَعْلَمُ أَنِّي إِنْ زِدْتُ عَلَى السَّبْعِينَ غُفِرَ لَهُ لَزِدْتُ قَالَ ثُمَّ صَلَّى عَلَيْهِ وَمَشَى مَعَهُ فَقَامَ عَلَى قَبْرِهِ حَتَّى فُرِغَ مِنْهُقَالَ فَعَجَبٌ لِي وَجَرَاءَتِي عَلَى رَسُولِ اللهِ ﷺ وَاللهُ وَرَسُولُهُ أَعْلَمُ قَالَ فَوَاللهِ مَا كَانَ إِلَّا يَسِيرًا حَتَّى نَزَلَتْ هَاتَانِ الْآيَتَانِ {وَلَا تُصَلِّ عَلَى أَحَدٍ مِنْهُمْ مَاتَ أَبَدًا وَلَا تَقُمْ عَلَى قَبْرِهِ إِنَّهُمْ كَفَرُوا بِاللَّهِ وَرَسُولِهِ وَمَاتُوا وَهُمْ فَاسِقُونَ} فَمَا صَلَّى رَسُولُ اللهِ ﷺ بَعْدَهُ عَلَى مُنَافِقٍ وَلا قَامَ عَلَى قَبْرِهِ حَتَّى قَبَضَهُ اللهُ ﷻ