The Prohibition of Prayer for the Funeral of Hypocrites
Allah says;
وَلَا تُصَلِّ عَلَى أَحَدٍ مِّنْهُم مَّاتَ أَبَدًا وَلَا تَقُمْ عَلَىَ قَبْرِهِ إِنَّهُمْ كَفَرُواْ بِاللّهِ وَرَسُولِهِ وَمَاتُواْ وَهُمْ فَاسِقُونَ
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 Fasiqun.
Allah commands His Messenger to disown the hypocrites, to abstain from praying the funeral prayer when any of them dies, from standing next to his grave to seek Allah's forgiveness for him, or to invoke Allah for his benefit.
This is because hypocrites disbelieved in Allah and His Messenger and died as such. This ruling applies to all those who are known to be hypocrites, even though it was revealed about the specific case of Abdullah bin Ubayy bin Salul, the chief hypocrite.
Al-Bukhari recorded that Ibn Umar said,
"When Abdullah bin Ubayy died, his son, Abdullah bin Abdullah, came to the Messenger of Allah and asked him to give him his shirt to shroud his father in, and the Messenger did that. He also asked that the Prophet offer his father's funeral prayer, and Allah's Messenger stood up to offer the funeral prayer. Umar took hold of the Prophet's robe and said, `O Allah's Messenger! Are you going to offer his funeral prayer even though your Lord has forbidden you to do so' Allah's Messenger said,
إِنَّمَا خَيَّرَنِي اللهُ فَقَالَ
I have been given the choice, for Allah says;
اسْتَغْفِرْ لَهُمْ أَوْ لَا تَسْتَغْفِرْ لَهُمْ إِن تَسْتَغْفِرْ لَهُمْ سَبْعِينَ مَرَّةً فَلَن يَغْفِرَ اللّهُ لَهُمْ
Whether you ask forgiveness for them (hypocrites), or do not ask for forgiveness for them. Even though you ask for their forgiveness seventy times, Allah will not forgive them. (9;80)
وَسَأَزِيدُهُ عَلَى السَّبْعِين
Verily, I will ask (for forgiveness for him) more than seventy times.
Umar said, `He is a hypocrite!'
So Allah's Messenger offered the funeral prayer and on that Allah revealed this Verse,
وَلَا تُصَلِّ عَلَى أَحَدٍ مِّنْهُم مَّاتَ أَبَدًا وَلَا تَقُمْ عَلَىَ قَبْرِهِ
And never (O Muhammad) pray (funeral prayer) for any of them (hypocrites) who dies, nor stand at his grave."
Umar bin Al-Khattab narrated a similar narration. In this narration, Umar said,
"The Prophet offered his funeral prayer, walked with the funeral procession and stood on his grave until he was buried. I was amazed at my daring to talk like this to the Messenger of Allah, while Allah and His Messenger have better knowledge. By Allah, soon afterwards, these two Ayat were revealed,
وَلَا تُصَلِّ عَلَى أَحَدٍ مِّنْهُم مَّاتَ أَبَدًا
And never (O Muhammad) pray (funeral prayer) for any of them (hypocrites) who dies.
Ever since this revelation came, the Prophet never offered the funeral prayer for any hypocrite nor stood on his grave until Allah, the Exalted and Most Honored, brought death to him."
At-Tirmidhi collected this Hadith in his Tafsir (section of his Sunan) and said, "Hasan Sahih".
Al-Bukhari also recorded it