I don't know if it's real and true, but I have heard that most of the people who died from the virus were in hospitals, most of the survivors were actually in their homes. one can say that being in a hospital affects your mental health by itself alone, of course the treatment in the hospital is another thing entirely.
However, I do think that when you are ill, your body doesn't work properly, including your emotions, the brain doesn't function very well when you are sick.
Now add all the drama related to this virus, all the negative news, the mere knowledge about the pandemic, and seeing how this virus is killing people all over the world is enough to affect your mental health. though having hope that you are going to be OK works too, but what they give you as medicine in the hospital is another factor in getting better sooner.