Suicide is the act of killing oneself intentionally. 
In Islam, suicide is one of the major sins, Allah (Glory be to Him) says in Qur’an.Surah Nisa 4:29 - And do not kill yourselves (nor kill one another). Surely, Allah (Glory be to Him) is Most Merciful to you.And the one who does that is faced with a warning of eternity in the Fire of Hell, where Allah (Glory be to Him) will punish him with the means that he used to commit suicide. It was narrated from Abu Hurayrah (May Allah be pleased with Him) that the Prophet Muhammad (May Allah honour Him and grant Him peace) said: “Whoever throws himself down from a mountain and kills himself will be throwing himself down in the Fire of Hell forever and ever. Whoever drinks poison and kills himself will be sipping it in the Fire of Hell forever and ever. Whoever kills himself with a piece of iron will have that iron in his hand, thrusting it into his belly in the Fire of Hell for ever and ever.” Sahih Al Bukhari Vol 7:670 andSahih Al Muslim 199.
Anas bin Malik® reported Allah's Messenger (May Allah honour Him and grant Him peace) as saying: None of you should make a request for death because of the trouble in which he is involved, but if there is no other help to it, then say: O Allah, keep me alive as long as there is goodness in life for me and bring death to me when there is goodness in death for me. Sahih Al Muslim 6480. 
Allah (Glory be to Him) says in Qur’an (interpretation of the meaning): "And We will surely test you with something of fear and hunger and a loss of wealth and lives and fruits, but give good tidings to the patient, Who, when disaster strikes them, say, "Indeed we belong to Allah , and indeed to Him we will return." Qur’an.Surah Baqarah 2:155-156.
So, it is clear from the ayath that the life of this world is a test according to Islam. By committing suicide, a person fails this test and will have to bear the result of his/her action in the Hereafter. A Muslim has to be patient and understand that no matter what hardship befalls him in this world, no matter how severe it is, the punishment of the Hereafter is a lot worse.
A believer is not allowed to lose hope in the Mercy of Allah (Glory be to Him), as stated in Qur’an: Allah (Glory be to Him) says (interpretation of the meaning) "Say: O My servants who have transgressed against their own souls, despair not of the Mercy of Allah. Indeed, Allah forgives all sins. Truly, He is Most Forgiving, Most Merciful." Qur’an.Surah Zumar 39:53
And so suicide is a major sin, as Allah (Glory be to Him) says in Qur’an (interpretation of the meaning): "Indeed, no one despairs of relief from Allah except the disbelieving people." Qur’an.Surah Yusuf 12:87 
If the believer handles the hardships and trials well and is patient, and it becomes a means that makes him turn back to Allah (Glory be to Him) and strive hard in worship and righteous deeds, then the calamity will have been good for him and will be expiation for his sins, and perhaps he will meet Allah (Glory be to Him) with no burden of sin.
The Prophet Muhammad (May Allah honour Him and grant Him peace) said: “No pain, hardship, sickness or grief befalls a believer, not even worry that befalls him, but some of his bad deeds will be expiated.” Sahih Al Muslim 6242. 
A person who has killed himself should be washed, prayed over and buried with the Muslims, because he is a sinner but he is not a kaafir (disbeliever). Killing oneself is a sin but it is not kufr. If he killed himself, he should be washed, shrouded and prayed over, but the khalifah (Leader of Muslim nation or people) and important people should not pray for him, by way of rebuke, lest anyone think that they approve of what he did. If the khalifah, ruler, judges, president or mayor do not pray over him in order to denounce this action and announce that it is wrong, then this is good, but some of the Muslims should still offer the (funeral) prayer for him.
Kitaab Majmoo’ Fataawa wa Maqaalaat Mutanawwi’ah li Samaahat al-Shaykh ‘Abd al-‘Azeez ibn ‘Abd-Allaah ibn Baaz (May Allah have mercy on him) – vol. 13, p. 122.