system
Given the following post, respond as if you're commenting on Reddit:
human
Where does the bacteria in our bodies come from and why is it allowed to exist?

The womb always struck me as a very sterile place. If a foetus hasn't yet developed its immune system and the mother gets a cold, the foetus wouldn't have any natural resistance to it. There's a tube that gives them nutrients and a hot tub without drink service, essentially a Mormon Cancun. 

Then at some point management catches on to its freeloading and it's kicked out. Suddenly it has to eat is own food, digest its own food, and perform all of the other functions that bacteria perform for us. Worst holiday ever.

So somewhere along the line a bacteria finds baby and decides that it's going to live in baby's intestinal tract like a miniature New Jersey. Hell yeah baby, I'm going to help you by digesting all of your food. Another bacteria comes along and assumes another function, then another, then yet another, and finally baby is more microbe than macrobe. 

What causes these bacteria to flock to us and why doesn't our immune system attack the more hostile ones, like the one in our mouth which converts sugar to acid and causes us to die at thirty from the resulting infections? Do we gain the bacteria over time from our diets or is it all transferred from mum to baby during its development?
gpt
List-based answer time!

1) The mother provides the child with IgG antibodies to fight most infections that she would get that could put the baby at risk. Bacteria won't cross from mother to child except in rare circumstances, and most of the time when the mother gets sick and the infection is bad the result isn't the death of the child via infection, it's spontaneous abortion (see: Listeria).

2) Natural births impart a giant load of bacteria to the newborn. The fetus is basically sterile, but the vagina is not a clean/sterile place. The uterus also has some bacteria that live in it. Natural births impart a lot of the mother's fecal bacteria to the baby because, let's face it, it's not exactly a pure and wholesome, sterile event.

3) C-section born children get some bacteria from their mother while being taken out, but also pick up bacteria from the people around them, the other babies in the nursery, and air.

4) Our body likes the bacteria within us. We're extremely tolerant to them and they help provide competition/natural defenses to other harmful bacteria. The commensals aren't hostile so there's no real reason for our immune system to go out of its way to fight against something that isn't harming us. They are pretty opportunistic though.

5) Die at 30 from infections from the bacteria in your mouth? What.