Anti-vaxxers compare the immune system with a muscle, requiring permanent training so that it does not wither away. This analogy is wrong!
FIRST, the immune system does not need to be challenged regularly (it will happen nevertheless).
SECOND, a better analogy is comparing the immune system with a cookbook.
At the beginning of life, our immune system is a book consisting of blank pages. With every (more severe) infection, starting in the womb, the immune system describes a page with a recipe on how to recognize and fight exactly this pathogen.
It uses different pens. The writing fades after some time with some pens, and we have to refresh vaccinations. If another infection occurs, the immune system uses a stronger pen—the receipt is "obviously" needed more often.
In addition, with each infection, the immune system refines the information. Thus, the immune response becomes broader, and the pathogen is still recognizable despite possible mutation.
In some chapters, such as "Influenza", the first page is written particularly bold—the "genetic original sin". That is why humans are particularly well protected against the first strain of flu that catches them.
Sometimes the pen pushes through to the next page. Then humans are also partially protected against similar pathogens. This effect is called cross-immunity.
There are also particularly severe infections that act as an eraser and erase immunities again .
The immune system cannot hold any number of pens simultaneously. If it is heavily engaged with one pathogen, it cannot write or read the pages for other pathogens—like in the case of superinfection. That is why giving antibiotics for viral infections and preventing bacterial pneumonia can make sense.
An infection always describes only one page, and against this pathogen, humans are more or less well protected afterwards. It does not influence others.
Passed through infections or immune reactions also do not ensure that the immune system can better describe other pages in the future (immunocompetence). Therefore, it makes no sense to strive for infection, besides all other disadvantages.
The book Immune: A Journey Into the Mysterious System That Keeps You Alive by Philipp Dettmer gives more details.