The mutualistic symbiosis relationship between the gut microbiome and their insect hosts has attracted much scientific attention. The native woodwasp, Sirex nitobei, and the invasive European woodwasp, Sirex noctilio, are two pests that infest pines in northeastern China. Following its encounter with the native species, however, there is a lack of research on whether the gut microbiome of S. noctilio changed, what causes contributed to these alterations, and whether these changes were more conducive to invasive colonization. We used high-throughput and metatranscriptomic sequencing to investigate S. noctilio larval gut and frass from four sites where only S. noctilio and both two Sirex species and investigated the effects of environmental factors, biological interactions, and ecological processes on S. noctilio gut microbial community assembly. Amplicon sequencing of two Sirex species revealed differential patterns of bacterial and fungal composition and functional prediction. S. noctilio larval gut bacterial and fungal diversity was essentially higher in coexistence sites than in separate existence sites, and most of the larval gut bacterial and fungal community functional predictions were significantly different as well. Moreover, temperature and precipitation positively correlate with most of the highly abundant bacterial and fungal genera. Source-tracking analysis showed that S. noctilio larvae at coexistence sites remain dependent on adult gut transmission (vertical transmission) or recruitment to frass (horizontal transmission). Meanwhile, stochastic processes of drift and dispersal limitation also have important impacts on the assembly of S. noctilio larval gut microbiome, especially at coexistence sites. In summary, our results reveal the potential role of changes in S. noctilio larval gut microbiome in the successful colonization and better adaptation of the environment.