Praise be to Allah.
Allah, may He be exalted, says (interpretation of the meaning):
“Certainly no one despairs of Allah’s Mercy, except the people who disbelieve”
This verse indicates that despairing of the mercy of Allah, may He be exalted, is one of the characteristics of the people who disbelieve, but this does not necessarily mean that someone who has one of their characteristics is a disbeliever like them.
Despair of the mercy of Allah, may He be exalted, may constitute disbelief that puts one beyond the pale of Islam, or it may be a major sin.
The guideline concerning that is that if despair leads to loss of hope of the mercy of Allah, may He be exalted, and His relief and pardon – for oneself or for other people – and it leads to denial or thinking it unlikely that Allah’s mercy, forgiveness and pardon can be all-encompassing, then this is disbelief, because it is an implicit rejection of the Qur’an and the definitive texts, and it is thinking ill of one’s Lord, may He be exalted, for He says – and His word is true – (interpretation of the meaning): “My mercy encompasses all things” [al-A‘raaf 7:156], but this person is saying that He will not forgive him! So he has regarded as limited that which is all-encompassing. This is applicable if he believes that, as Imam al-Qurtubi (may Allah have mercy on him) said in his Tafseer (5/160).
But if he thinks that his sins are too great and that it is unlikely that he will be forgiven or pardoned for them, or with regard to the divine decree and control of the universe he despairs with regard to provision, children and the like – without losing all hope – then this is a major sin, but it does not constitute disbelief. It is regarded as being a major sin – according to scholarly consensus – because of the stern warning that has been narrated concerning it, such as the verses in which Allah, may He be exalted, says (interpretation of the meaning): “Certainly no one despairs of Allah’s Mercy, except the people who disbelieve” [Yoosuf 12:87] and “And who despairs of the Mercy of his Lord except those who are astray?” [al-Hijr 15:56]. And Allah knows best.
For more information, please see: Tafseer al-Qurtubi (5/160); az-Zawaajir ‘an Iqtiraaf al-Kabaa’ir by Ibn Hajar al-Haytami (no. 40); Sharh al-‘Aqeedah at-Tahhaawiyyah by Shaykh Saalih Aal ash-Shaykh (1/552); al-Mawsoo‘ah al-Fiqhiyyah al-Kuwaitiyyah (7/200)
And Allah knows best.