The hygiene hypothesis is widely accepted, including by allergists, and there's definitely data supporting it, but we don't understand the mechanism, so it's hard to say that it's about any one specific thing vs. many contributing causes that correlate with hygiene and other aspects of the environment around the kid.
The advice about early exposure clearly works though, and there's data to support that early exposure even after confirming the allergy can increase the chances of outgrowing the allergy.
As lymphocytes are formed, they randomly rearrange their T-cell receptor / immunoglobulin genes, creating a random antigen specificity for each cell. [1]
Then, they get selectively killed if they react to self-antigens. [2]
Those that survive, if they ever meet their specific antigen, will selectively multiply [3] and do random mutations again [4].
[1] https://en.wikipedia.org/wiki/V(D)J_recombination
[2] https://en.wikipedia.org/wiki/Clonal_deletion
[3] https://en.wikipedia.org/wiki/Clonal_selection
[4] https://en.wikipedia.org/wiki/Somatic_hypermutation
The current theory is that allergies appear if: (1) some random lymphocyte rearrangement created affinity for that allergen and (2) the allergen was not "known to be safe" by the selection mechanisms of the body and that lymphocyte was allowed to survive.There's also the ones that react weakly to self antigens and are kept around to put a check on everything else.
https://en.wikipedia.org/wiki/Regulatory_T_cell
The thymus is just insane.