Bacterial viruses, that is ‘bacteriophage’ or ‘phage’, can infect and lyse their bacterial hosts, releasing new viral progeny. In addition to the lytic pathway, certain bacteriophage (i.e. ‘temperate’ bacteriophage) can also initiate lysogeny, a latent mode of infection in which the viral genome is integrated into and replicated with the bacterial chromosome. Subsequently, the integrated viral genome, that is the ‘prophage’, can induce and restart the lytic pathway. Here, we explore the relationship among infection mode, ecological context, and viral fitness, in essence asking: when should viruses be temperate? To do so, we use network loop analysis to quantify fitness in terms of network paths through the life history of an infectious pathogen that start and end with infected cells. This analysis reveals that temperate strategies, particularly those with direct benefits to cellular fitness, should be favored at low host abundances. This finding applies to a spectrum of mechanistic models of phage–bacteria dynamics spanning both explicit and implicit representations of intra-cellular infection dynamics. However, the same analysis reveals that temperate strategies, in and of themselves, do not provide an advantage when infection imposes a cost to cellular fitness. Hence, we use evolutionary invasion analysis to explore when temperate phage can invade microbial communities with circulating lytic phage. We find that lytic phage can drive down niche competition amongst microbial cells, facilitating the subsequent invasion of latent strategies that increase cellular resistance and/or immunity to infection by lytic viruses—notably this finding holds even when the prophage comes at a direct fitness cost to cellular reproduction. Altogether, our analysis identifies broad ecological conditions that favor latency and provide a principled framework for exploring the impacts of ecological context on both the short- and long-term benefits of being temperate.