In a way. Mental illnesses aren't necessarily "contagious," but if people around you are depressed, you can become depressed yourself for a period of time. Mental illnesses are a result of chemical imbalances in the brain that people are born with or a result of a traumatic experience in one's life.
I suffer from anxiety and depression, two things of which I was born with and then intensified after a traumatizing childhood. Mental illnesses are not contagious unless there is a history of mental illness in one's family. But yes, if people around you seem depressed or axious, for a short while, or even a long while, you could also feel depressed and anxious.