When indoors, they are exposed to lesser germs and infections as they are in a safe environment. They need not touch infected items or surfaces. They are not exposed to pollution or even infected people. This will bring down the chances of the child contracting any infection or falling sick unnecessarily.
When they are outdoors, they are definitely exposed to a number of known and unknown germs and infections. When they are exposed to other children, they learn from them and adapt as per the requirement.
However, this makes the child resilient and improves immunity naturally. When the body is exposed to a particular virus or infection, it learns how to cope up and thus becomes immune to it in the long run.
When children come in contact with dirt and other infected children, their body develops the immunity to keep them safe. They can learn things you can't teach or are not aware of yourself.