If you get, say, depressed because of your life being constant shit, how will going to a mental institution help? How does therapy help?

It’s not like therapy is going to solve the problems you face in life, like lack of money, friends, bad job, etc? I guess I’m asking what is the purpose of therapy and mental institutions?