Killing oneself is a major sin, and there are stern warnings addressed to the one who does that, but it does not put one beyond the pale of Islam. In the Sunnah it shows that it is permissible for ordinary people to offer the funeral prayer for one who commits suicide, but it is prescribed for the elite, such as scholars and prominent figures, not to offer the funeral prayer for him, as a rebuke and so as to deter others from doing likewise. It was narrated that Jaabir ibn Samurah said: A man who had killed himself with a broad, sharp-edged arrow was brought to the Messenger of Allaah (peace and blessings of Allaah be upon him) and he did not offer the funeral prayer for him. Narrated by Muslim (978).
The scholars said: this hadeeth is to be understood as a deterrent to suicide, just as he did not offer the funeral prayer for one who was in debt, but the Sahaabah offered the funeral prayer for the debtor on the command of the Prophet (peace and blessings of Allaah be upon him). That was in order to deter others from getting into debt, not because he was a kaafir. According to Maalik it is makrooh to offer the funeral prayer for one who has been stoned to death as a hadd punishment, and one who was immoral, as an expression of disapproval.
Sharh Muslim, 7/47.
Shaykh al-Islam Ibn Taymiyah was asked about a man who claimed to be a holy man, then he saw a snake and some of the people wanted to kill it, but he stopped them, then he picked up the snake trying to do a miraculous deed, but the snake bit him and he died. Is it permissible to offer the funeral prayer for him or not?
Praise be to Allaah, the Lord of the Worlds. The scholars and people who are religiously committed should not pray for this man and others like him, but the ordinary people should pray for him, just as the Prophet (peace and blessings of Allaah be upon him) refrained from praying for a man who had committed suicide, and one who had stolen from the war-booty, but he said: âPray for your companion.â They said to Samurah ibn Jundub: âYour son did not sleep last night.â He said, âWas it because he ate too much?â They said: âYes.â He said: âIf he had died I would not have prayed for him.â Samurah explained that if he died because he had eaten too much, he would not pray for him, because he would have killed himself by eating too much. And it is more appropriate that the scholars and those who are religiously-committed should refrain from offering the funeral prayer for this man who prevented others from killing the snake, and held it in his hand until it killed him, because he killed himself.
Al-Fataawa al-Kubra, 3/20, 21
Shaykh al-Islam also said:
If a person refrains from praying for one of them â i.e., the one who stole from the war-booty, the one who killed himself and the debtor â as a deterrent to others from doing likewise, then that is good. But if he refrains from praying for him in public but makes duâaaâ for him in private, then he will achieve two ends, which is better than omitting one of them.
Al-Ikhtiyaaraat al-âIlmiyyah, p. 52.
Shaykh âAbd al-âAzeez ibn Baaz was asked:
Can the funeral prayer be offered for one who kills himself?
Some of the Muslims should pray for him, as for any other sinner, because he is still a Muslim according to Ahl al-Sunnah.
Majmooâ Fataawa al-Shaykh Ibn Baaz, 13/162.
And he was asked:
Should one who killed himself be washed and the funeral prayer offered for him?
The one who killed himself should be washed and the funeral prayer offered for him, and he should be buried with the Muslims, because he is a sinner, but he is not a kaafir; killing oneself is a sin, it is not kufr.
If a person kills himself â Allaah forbid â he should be washed and shrouded, and the funeral prayer offered for him, but the ruler and important figures should refrain from offering the funeral prayer for him as an act of denunciation, lest anyone think that they approve of what he did. If the caliph, ruler, judges, governor, mayor etc do not offer the funeral prayer for him as an act of denunciation and a declaration that this was wrong, then that is a good thing, but some of the worshippers should offer the prayer for him.
Majmooâ Fataawa al-Shaykh Ibn Baaz, 13/122; Fataawa Islamiyyah, 2/62
And Allaah knows best.