A lot of comedy comes from pain. I think Peter McGraw's benign violation theory partially explains this. According to McGraw's theory, humor comes from a "violation" or something negative that is made benign. Comedians learn to take the negative and transform it into something humorous.
People also say that many comedians have a more realistic view of the harshness of life. This reminds me of the quote from GK Chesterton, “Always be comic in a tragedy. What the deuce else can you do?"
A large number of comedians are depressed in real life, away from audiences and cameras. I met a relatively famous comedian and he was quite depressed, and definitely not the only one.
In our industry or technology, depression, burnout, mental illness are all areas I don't feel we deal with very well.