Foods can soften the enamel and if you brush it right away it can wear off the enamel, by rinsing your teeth you neutralize the acid, then calcium from your saliva gets a chance to rebuild the enamel. Brushing gets rid of the food debris, our mouth is full of bacteria they consume the same food that you eat, and their wastes are acidic, that acid makes holes in your teeth causing cavities!
Make sure you do not forget about flossing! Brushing with out flossing is literally not good enough!
I take the chance to mention water flossing is awesome but doesn’t replace manual flossing.