It's both. Many likely have some pre-existing mental condition, maybe completely latent or or maybe just early in onset. Awful life conditions combined with substance abuse then lead to a feedback loop exacerbating the mental illness, substance abuse, and shitty choices.