The gut-brain axis is officially a thing. Evidence is accumulating that the gut microbiome, and perturbations in it, can affect behavior—at least in mice. New work is starting to unravel how.
Normally, animals can adapt to changes in their environments with corresponding changes in their behaviors. One well-studied example is what's called "fear extinction learning." Animals can be taught to associate harmless things like a sound or lights with a negative outcome. But, if that association changes over time, they can also forget it.
To be more specific, animals can be trained to associate a tone with a painful shock; when they hear the tone, they freeze in fear. But they can be retrained by exposure to the tone without the shock. Eventually, they learn that the tone is OK, and when they hear it, they just blithely go about their business.