As you are no doubt aware, the immune system has many ways in which it causes problems for humans, rather than the bacteria, viruses etc. it should be focusing on.
We call this ‘auto-immune’ disease. Depending on the area affected, auto-immune disorders get different names (for example, rheumatoid disease affecting joints, psoriasis affecting skin, and so on) but it is all the same issue.
Traditionally, when it comes to the mind and psychological or psychiatric disorders, the assumption has always been that the problem is localised in the brain itself, with or without ‘stress’ or adverse life experiences as a cause or trigger.
The idea that the immune system could attack or interfere with the brain enough to cause depression, or psychosis (for example) has not been recognized except in the last 5 years or so.
For example, some new research in January 2018.
Or listen to this excellent podcast from the BBC for some more information.