Children get shots to protect, or give them immunity, from vaccine preventable illnesses.
These vaccines that children get also protect other people who aren't immune from these infections, either because they don't get vaccinated, their vaccine wasn't effective, or because they have become immunocompromised.
This works because of the concept of herd immunity, in which if most people around you are immune to an infection and can't get sick, then there is no one around to infect you, even if you aren't immune to the infection.
For example, rates of invasive disease caused by the Streptococcus pneumoniae bacteria went down in unvaccinated children after the Prevnar vaccine began to be routinely used. This is likely because of the herd immunity effect of the kids who were vaccinated with Prevnar.
Herd immunity only works if immunization rates in a community are high though, and can range for 85% for diphtheria to 92% for pertussis or whooping cough.
Sources:
Plotkin: Vaccines, 4th ed.
Cost-effectiveness of pneumococcal conjugate vaccine: evidence from the first 5 years of use in the United States incorporating herd effects. Ray GT - Pediatr Infect Dis J - 01-JUN-2006; 25(6): 494-501

