Humour can be used to mask emotional problems but the people using it aren’t always mentally ill. They’re caught in a situation where they’re trying to find a socially acceptable outlet for it but not so many have the maturity to use humour to not only alleviate themselves but to move past it.
Somebody who uses affiliative and/or self-enhancing humour has the maturity to not only cope with problems most of the time but also to move past them. The user still has issues but needn’t to mock others or oneself often. The latter types, aggressive and self-defeating, however indicate immaturity in coping with problems.
The users try their hardest but it backfires as some get offended. That’s like the difference between writing stories to try to forgive people and writing stories to demean people, which I’ve been through myself. It’s good to use humour but it takes maturity to move past the need to belittle others to finally get over bad feelings well enough.