IMO the simpler hypothesis here is that this isn’t anything adaptive, it’s just another example of how biology is like spaghetti code; changing one chemical signal will affect an essentially random set of downstream systems, some of which can be causally connected to psychology/behavior.
So, is microbiome-mediated social anxiety selected for as an advantageous trait for societies subject to communicable diseases and the travails of nomadism? Maybe. Did YOUR microbiome-mediated social anxiety arise because it was advantageous for your community? Probably impossible to say.
Also, a hole in GP's logic: you would expect protective social anxiety to arise in people whose situation hasn't much changed except that they've encountered people whose has (as with sedentary villagers encountering nomads who may or may not be about to ransack their settlement).
No, you would not expect that. If rats that self-isolate when their gut micro-biomes change avoid diseases that other rats get afflicted with, then evolution will lead to the mechanism spreading through the rats over time. The rats do not need to know why self-isolating helps, they do not need to even know that self-isolating helps, and they do not need to be in the position where it would help the most.
Nothing you said contradicts this, and I'm not sure how to square the circle, even though microbiome-mediated behavior as an explanation for broad, otherwise irrational behavior patterns is attractive.
That's not a competing hypothesis. Obviously the change to the gut affects other things, some of which happen to impact psychology and behavior.
The question is why does this particular change to gut microbiome have such a similar impact on two different species that diverged many tens of millions of years ago? "It just does" is not a very satisfying answer.
If you look closely enough, even individuals aren't the true units of evolution, for the same reason; competing alleles is where the real action is.
It's only when an effect causes death or infertility prior to normal reproductive phases that we can really say it has a direct evolutionary pressure. Anything that happens later is always going to be through secondary, social effects on how their condition supports or hinders their offspring from reproducing further generations.
E pur si muove.