Gut bacteria can influence mental health by producing neurotransmitters like serotonin and dopamine, which affect mood and cognitive functions. Changes in gut microbiota can impact stress responses, memory, and overall mental health.