Muslim (978) narrated that Jaabir ibn Samurah said: A man who had killed himself with an arrow was brought to the Messenger of Allaah (peace and blessings of Allaah be upon him), but he did not offer the funeral prayer for him.
Abu Dawood (2710), al-Nasaa’i (1959) and Ibn Maajah (2848) narrated from Zayd ibn Khaalid al-Juhani that one of the companions of the Prophet (peace and blessings of Allaah be upon him) died on the day of Khaybar. The Messenger of Allaah (peace and blessings of Allaah be upon him) was told about that and he said: “Offer the funeral prayer for your companion.” The people’s expressions changed (i.e. they did not know why the Prophet (peace and blessings of Allaah be upon him) was not going to lead the funeral prayer himself). He said: “Your companion stole from the war booty (when fighting) for the sake of Allaah.” We searched his belongings and found some pearls from the pearls of the Jews that were not even worth two dirhams.
The scholars understood from this hadeeth that the Sunnah is for the ruler not to offer the funeral prayer for one who stole from the war booty or one who killed himself, following the example of the Prophet (peace and blessings of Allaah be upon him).
Here two questions arise:
1 – Should people of knowledge and virtue follow the ruler’s lead?
2 – Should others who are like the one who stole from the war booty or one who killed himself, or worse than them – such as bandits, oppressors and those who commit major sins or commit sin openly – be treated in like manner?
The answer is: Yes, people of knowledge and virtue should follow the ruler’s lead, and others who are like the one who stole from the war booty or one who killed himself, or worse than them, should be treated in like manner.
Al-Baaji said in al-Muntaqa: This is the Sunnah, rulers and people of virtue should refrain from offering the funeral prayer for those who committed major sins, as a deterrent against doing similar actions. The fact that he (the Prophet (peace and blessings of Allaah be upon him)) commanded others to offer the prayer for him indicates that they come under the heading of believers and are not regarded as non-believers because of the sins they committed. End quote.
Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said: If a person who did not pay zakaah and did not pray except in Ramadaan dies, the people of knowledge and religious commitment should refrain from offering the funeral prayer for him as a punishment and a rebuke to those who are like him, because the Prophet (peace and blessings of Allaah be upon him) refrained from offering the funeral prayer for one who had killed himself, one who had stolen from the war booty, and a debtor who had died without paying off his debt.
But some people must offer the funeral prayer for him… If a person who committed sin openly but still had some faith died, like those who commit major sins, and someone refuses to offer the funeral prayer for him as a rebuke to others who are like him, he has done well. If a person offers the funeral prayer for him in the hope that Allaah will have mercy on him, and because there is no purpose to be served by refraining from offering the prayer for him, he has also done well. If a person refuses outwardly to offer the funeral prayer for him but makes du’aa’ for him in secret in order to achieve both purposes, that is better than missing out on one of them. End quote.
Source