(Better late than never.)

The lungs have an intrinsic mechanism for clearing the gunk (official term "sputum," once called "phlegm") automatically: the surface layer of cells in the bronchi (epithelium) has little hairlike extensions (cilia, pl of cilium) that sweep any adherent mucus, plus whatever germs or cellular debris may be in it, up and out. That's what we're doing when we clear our throat—get the gunk out into the mouth, so we can expectorate it or swallow it, but either way it's out of our lungs. This process is helped along by coughing, which hurls the sputum further up and out faster. Toxins (see * below) or infections or other noxious influences can paralyze this ciliary mechanism, temporarily or permanently.

Sedatives, or strokes or other neurological damage, or drinking, can impair or paralyze the cough mechanism.

Age, or sedatives, or alcohol, or strokes big or mini-, can interfere with swallowing mechanisms so that mouth organisms fail to be diverted away from the lungs, and pathogens can be introduced that would ordinarily be shunted elsewhere.

Mouth breathing has nothing to do with anything except that the nasal passages moisten the air on the way into the lungs. They also filter out the largest of particles; some are caught in the hairs, and some stick to the moist surfaces in the upper airway. Air that is too dry can parch the lungs and render them more susceptible to infection, but that's not a major factor.

Nursing homes may have more than the usual percentage of pathogens in the ambient environment because of a lot of antibiotics (necessary ones, we trust) having eliminated the competing susceptible commensal organisms, leaving more pathogens (and often selecting for the drug-resistant ones).

* (Btw, cigarette smoke is one such inhibitor of normal ciliary activity. Anybody ever notice that your "smokers' cough" often begins a day or two after stopping? ["I never coughed like this while I was smoking!"] The reason is that it takes that long for the cilia to regain their activity, so that now, for the first time in years, they can resume their normal function of clearing out the crud that's been accumulating all this time...)