It’s to protect our stomach and organs from the hydrochloric acid in our stomachs.
The acid is very corrosive and will dissolve a wide array of organic materials, including our own flesh. The coating of mucus allows for us to eat our food to be digested without being eaten inside-out by our own stomach juices