Why do ear infections mostly affect babies and children?

Maturity. Ear infections are thought to result from a poorly functioning eustachain tube which connects the middle ear to the nose. As one ages the tube matures.It gets larger making it less likely to obstruct. It is this blockage that causes ear infections.In addition, it is probable that the immune systems matures, fighting the infections off more efficiently.
Anatomy. May i also add the fact that not only do the eustachian tubes get larger, they also incline themselves and that serves a better purpose of draining any middle ear fluid to the throat.