All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger.
In principle, committing suicide is one of the gravest major sins, however it does not take the one who commits it outside the fold of Islam.
As for this person, if he committed suicide due to unbearable pain or despair then he wronged himself, because what he did is considered intentional murder. This action, as we stated, is one of the gravest major sins. In this regard, it was reported on the authority of Abu Hurayrah that during the battle of Hunayn, the Prophet, sallallaahu ‘alayhi wa sallam, mentioned a man who claimed to be a Muslim who would be a resident of Hell. During the battle, that man fought valiantly and was wounded. Therefore, the Companions told the Prophet, sallallaahu ‘alayhi wa sallam, that the man had fought valiantly for Islam until he died.
However, the Prophet, sallallahu ‘alayhi wa sallam, told them that he would be a dweller of Hellfire. This put some men on the verge of doubt. While they were in that state, they were told that the man had not died but was fatally wounded. When it was night, the man could not bear the pain of his wound and killed himself. When the Prophet, sallallaahu ‘alayhi wa sallam, was told about that, he said the following: "Allaah is Greatest, I testify that I am the slave of Allaah and His Messenger." Then he commanded Bilaal to announce to the people that no one but a Muslim would enter Paradise and that Allaah supports this religion, even with a dissolute person. [Al-Bukhari and Muslim]
However, if this person committed suicide while he was in a state of delirium and insanity then he incurs no sin. In this regard it was reported that the Prophet, sallallaahu ‘alayhi wa sallam, said that Allaah The Almighty would not hold three types of people accountable for their deeds: a sleeping person until he wakes up, a minor until he reaches the age of puberty, and an insane person until he regains his sanity. [Ahmad].
Allaah Knows best.