Investigations of gut microbiomes have shed light on the diversity and genetic content of these communities, and helped shape our understanding of how host-associated microorganisms influence host physiology, behavior, and health. Despite the importance of gut microbes to metazoans, our understanding of the changes in diversity and composition across the alimentary tract, and the source of the resident community are limited. Here, using community metagenomics and 16S rRNA gene sequencing, we assess microbial community diversity and coding potential in the foregut, midgut, and hindgut of a juvenile Panchlora cockroach, which resides in the refuse piles of the leaf-cutter ant species Atta colombica. We found a significant shift in the microbial community structure and coding potential throughout the three gut sections of Panchlora sp., and through comparison with previously generated metagenomes of the cockroach's food source and niche, we reveal that this shift in microbial community composition is influenced by the ecosystems in which Panchlora sp. occurs. While the foregut is composed of microbes that likely originate from the symbiotic fungus gardens of the ants, the midgut and hindgut are composed of a microbial community that is likely cockroach-specific. Analogous to mammalian systems, the midgut and hindgut appear to be dominated by Firmicutes and Bacteroidetes with the capacity for polysaccharide degradation, suggesting they may assist in the degradation of dietary plant material. Our work underscores the prominence of community changes throughout gut microbiomes and highlights ecological factors that underpin the structure and function of the symbiotic microbial communities of metazoans.