In this study, we investigated the protective mechanism of walnut-derived peptide LPLLR (LP-5) against cognitive impairment induced in a dextran sodium sulfate (DSS)-induced colitis mouse model, with emphasis on the microbiota-gut-brain axis (MGBA). The results revealed that LP-5 could improve the learning ability and memory of mice with cognitive impairment and mitigate colitis symptoms, including weight loss, bloody stools, colon shortening, and histopathological changes. Additionally, LP-5 protected the integrity of the intestinal barrier by promoting the expression of tight junction proteins (TJs) while attenuating colonic inflammation by suppressing proinflammatory cytokine and epithelial cell apoptosis. Western blotting indicated that LP-5 treatment suppressed the inflammatory NF-κB/MLCK/MLC signaling pathway activity. Furthermore, LP-5 ameliorated hippocampal neuron damage and protected blood-brain barrier (BBB) integrity by downregulating microglia marker protein Iba-1, increasing TJ protein expression, and restoring the deterioration of synaptic proteins. Importantly, 16S rRNA sequencing results indicated that LP-5 reshaped the abundance of a wide range of gut microbiota at the phylum and genus levels, with increased Prevotella and Akkermansia associated with tryptophan (TRP), 5-hydroxytryptamine (5-HT), and 5-hydroxyindoleacetic acid (5-HIAA). These findings suggest that LP-5 could maintain intestinal barrier and BBB integrity, reverse gut dysbiosis, and improve learning and memory ability in colitis mice, providing novel insights into alterations of gut microbes in colitis and a potential new mechanism by which it causes cognitive impairment.