Pangenomes vary across bacteria. Some species have fluid pangenomes, with a high proportion of genes varying between individual genomes. Other species have less fluid pangenomes, with different genomes tending to contain the same genes. Two main hypotheses have been suggested to explain this variation: differences in species' bacterial lifestyle and effective population size. However, previous studies have not been able to test between these hypotheses because the different features of lifestyle and effective population size are highly correlated with each other, and phylogenetically conserved, making it hard to disentangle their relative importance. We used phylogeny-based analyses, across 126 bacterial species, to tease apart the causal role of different factors. We found that pangenome fluidity was lower in i) host-associated compared with free-living species and ii) host-associated species that are obligately dependent on a host, live inside cells, and are more pathogenic and less motile. In contrast, we found no support for the competing hypothesis that larger effective population sizes lead to more fluid pangenomes. Effective population size appears to correlate with pangenome variation because it is also driven by bacterial lifestyle, rather than because of a causal relationship.