Sometimes it's exactly as you said. An unbearable pain of the mind -- we are less judgmental towards people who feel unbearable pain of the body and want to die.
But sometimes, they do it because they believe the world is better off without them. They believe they are worthless, or even of negative value.
And I would argue that, most of the time, it is not they who are negative, but the judgmental people who bully them even more for their struggles.