The immune system apparently learns very efficiently to distinguish "own" from "fremd″".
However, when the body uses its immune system not only against foreign influences (such as bacteria, viruses, proteine), but also against the body's own components, diseases develop that take a chronic course and are difficult to treat.
https://de.wikipedia.org/wiki/Autoimmunerkrankung (Wikipedia CC-by-sa-3.0)