You could argue that the toilet and its support infrastructure is the the most important public health measure ever developed.
The question is "why is it so effective?" WRT non-viral undesired health states
It seems obvious but really it is much more nuanced than it seems.
People carry all sorts of bacteria both inside and outside. People do all sorts of epidemiologically outrageous things, like kiss, have sex, touch doorknobs and toilet seats, share food, kiss their dogs and cats, go to hospitals. pick their noses, shake hands, go the public school, day care and any number of other unmentionable things.
But mostly it is relatively hard to link them to health issues. It seems being exposed to a constant barrage of microbes isn't a problem in itself except with respect to those rare microbes that have adopted a "burn down the house to keep warm" evolutionary path.
What does seem to be risky is when microbes are subjected to conflicting sensory input, a barrage of potential genetic material, and conflicting/different selective pressures associated with other hosts or living in human/animal waste products.
Microbes are cooperative with us when we train them properly to be that way either consciously or unconsciously. The toilet works not by preventing exposure although this is sometimes important for already created "burn down the house to keep warm" microbes. Toilets work because they force closer association of microbes with their hosts = host dependency.
Bacteria being spread by doorknobs, toilet seats just sit there and don't really change much while they wait. Bacteria spread by normal kissing, sex and other human activities are already host associated, and must compete with already entrenched bacterial microbiota.
But when microbes can live, die and compete for life in other hosts and in human waste products they are pushed chaotically away from host dependence in all sorts of directions, and eventually combinations arise that can displace our entrenched microbiota and recolonize and/or incite a civil war and/or "burn down the house to keep warm".
We do have some control over this process. The toilet is one example. We force close association with the host by making the host the only place where mixing and growth can occur and we prevent our microbiota from gaining a niche in the local environment where divergent selection and host switching can occur. Another example in the other direction is prostitution, especially the heavily monetized and exploitative version which is a worst case scenario. Essentially prostitutes become waste depositories (semen) where both environmental growth and mixing of many microbes occur many times daily over many days.
Another example is farms where animals have long and direct contact with wastes with a rich microbial population and can often achieve semi-host independence. Change happens as environmentally adapted members of a species acquire enough genetic change to displace diverse host dependent members of the same species. Hence they are clonal, relatively environmentally adapted and are not good at cooperation with the host, and make errors in assessing host health state. This is the only reason simple vaccines work. The problem population is emergent, clonal and do not know their host well enough to evade educated immune response.
However when we push the system too far and long enough we create emergent microbes that are both invasive and can evade educated immune response. If we treat the animals poorly enough, even the host adapted microbiota get enough conflicting sensory input that they cause issues. There is no possible vaccine remedy for this as the entrenched host dependent population is both genetically diverse and cooperatively triggered to virulent state once one of them gets triggered. No single isolate vaccine can protect against this, or prevent emergent microbial recolonization.
Antibiotics generally do not achieve microcidal concentrations in patients. What they do is shift the balance towards the host and the already entrenched microbial population when which generally have huge numerical, species and genetic diversity advantages. However, when a non-host dependent clonal emergent isolate acquires antibiotic resistance AND that particular antibiotic is given, the opposite happens and the diverse host dependent population is heavily disfavored, and numerical superiority occurs = worst case scenario.
The move from mixed species farms to uni-species farms was a directed or serendipitous semi-solution to this problem. Uni-species farms promote close microbial host dependency. So what about adding antiibiotics to animal feeds? The result depends on the state of the entrenched microbiota. If the entrenched microbiota is diverse, entrenched and already resistant to the antibiotic it tends to have a neutral or stabilizing effect as it excludes competitors that may be less host dependent/adapted and not resistant to the antimicrobial. However treating with an antimicrobial that the entrenched host adapted microbiota are not already resistant to has a destabilizing effect. Removing an antibiotic that the entrenched microbiota are resistant to would also have a destabilizing effect with possible colonization of emergent environmentally adapted groups that are already capable of displacing entrenched communities but are held in check by the antibiotic. A prediction of outbreaks seems reasonable with loss of diversity and emergence of clonal isolates that may or may not be resistant.
So why it this entire logic experiment perhaps descriptive for bacteria and not for viruses or protozoa?
Because viruses are too simple to form a synergistic or neutral* relationship with hosts and thus gravitate wildly between being invisible and spreading like a fire. Protozoa on the other hand are usually too complex and too much like us for synergy. Bacteria have just the right complexity to form stable neutral or synergistic relationships with animals,
In essence the dynamics of the relationship between bacteria and animal hosts can be described by the following question:
When does it makes sense to burn down your house to keep warm?
Bacteria sense, modulate their genes, compete and are naturally selected along the lines of the following answers.
1) When your house is already on fire
2) When you can't tell if your house is on fire or not.
2) When there are many near identical homes nearby that are empty
3) When there are many near identical homes nearby that are not empty but you can take
4) When you get a new neighbor with an AK47 collection and a dedication to Darwinism
5) When somebody aggressive moves in and you have nothing to lose by trying to burn them out.
*Neutral means taking up space and thereby excluding competitors while not causing too much trouble.