No one knows the origins of the bacteria that came to be inside of the human gut. On the other hand, it is known that the bacteria inside of the guts of modern apes are very similar to ours. This means that the bacteria have coexisted within the lineage of hominids. The micro biomes must have evolved simultaneously with the hominids at some point in our common ancestors. In a study done by Moller et al. the feces of wild chimpanzees, bonobos, and gorillas to assess the gene sequences within. They developed a method to compare genes within amongst species to determine the composition of the microbiota.
The results showed that the bacteria must have evolved simultaneously only at the common ancestor of Hominid and the African Ape. They showed that there is a minimum age of these bacterial symbioses. It is plausible that there would be similar trends at each of the branches throughout the evolution of all vertebrates. It has exposed an impressive clue in the mystery of the coevolution between vertebrate and their gut buddies.
Several of my classmates have explained the roles of microbiota with several immune system functions. This means that as hominids immune systems were evolving, so were the bacteria. They were altering it. Hosts have evolved response to the bacteria living inside them and have even deeper linkages to our immune system