The basic rationale for it is that the human genome did not evolve in a sterile environment, it evolved in an extremely hostile environment, and so developed pretty harsh defense mechanisms, which if not trained (via early exposure) on the appropriate targets will instead learn to target harmless compounds as well as the body itself.
I see it as more of a side effect of an immune system that is designed to adjust itself for whatever pathogens are present in its environment.
Depending on where you are born, you can be exposed to a completely different set of microorganisms or compounds present in the environment. Your body first needs to know which of those are benign and not. A simple heuristic is to tolerate most of these that you have been exposed to till a certain age.
But hey this is just my armchair biology. Don't know if there is anything supporting it
https://en.wikipedia.org/wiki/Hygiene_hypothesis
The basic rationale for it is that the human genome did not evolve in a sterile environment, it evolved in an extremely hostile environment, and so developed pretty harsh defense mechanisms, which if not trained (via early exposure) on the appropriate targets will instead learn to target harmless compounds as well as the body itself.