Like, where did they live before there were termites to live in?
Termites are just cockroaches that have learned to cooperate very well. They are thought to have begun as something like the wood-feeding cockroach genus Cryptocercus. The microbes that live so successfully in their guts are derived from similar free-living forms in rotting logs that get eaten when cockroaches eat the rot. So both the ancestoral microbes and the ancestoral cockroaches were living in logs and soil well before termites came about. You can imagine a termite as a streamlined cockroach shaped by the needs and profit of the microbes as well as the benefits of living in social groups. Over time, the gut organisms became adapted to their unique habitat and co-evolved tightly with their hosts to the point that most are critical for the termites’ success.