The United Kingdom and European Union have banned crates for pregnant sows. However, animals are kept in a restrictive environment for up to four weeks after mating, leading to stress and different responses of the animals’ immune system. Here, we used vaginal flushing of gilts to investigate whether housing systems or an experimental inflammatory challenge with lipopolysaccharide (LPS) can modify the gilt vaginal microbiome. Alpha-diversity indices showed differences in the microbiota of gilts housed under different systems (q = 0.04). Shannon alpha-diversity richness was higher in gilts group-housed in pens than in gilts housed in crates (q = 0.035), but not higher than in other groups. The relative abundance of the operational taxonomic unit (OTU) (q < 0.05) revealed specific differences in housing systems before a LPS or saline (SAL control) challenge. We found different abundances in taxa of Actinobacteria, Bacteroidetes, Cyanobacteria, Firmicutes, and Proteobacteria in gilts housed in the different systems before challenge. After the LPS challenge, significant differences were detected in the relative abundance of OTUs (q < 0.05) for the LPS-challenged group compared with SAL animals for each housing system. The phylum Staphylococcus showed higher abundance among the LPS-challenged gilts than in SAL-challenged animals. Furthermore, Enterobacter was more abundant in the LPS-challenged gilts housed in crates than in SAL-challenged gilts housed in crates. Streptococcus suis, Conchiformibius, Globicatella and Actinobacillus were more abundant in LPS-challenged gilts in indoor group housing than in SAL gilts in the same housing system. Gilts kept outdoors did not show changes in vaginal microbiota after an LPS challenge. Gilts housed in crates showed clinical signs of urogenital infection, whereas gilts housed outdoors and in indoor group housing did not. The relationship between environment, immune response, and microbiota suggested that animals in a poor environments experience difficulties responding to a challenge and their vaginal microbiota is altered as a consequence, with decreased richness of normal vaginal microbiota, and increased opportunistic bacteria. Welfare indicators measured by gilts’ responses to housing systems however, do not fully explain mechanisms associated with the unique signature in vaginal microbiota encountered in the different housing systems.