They were taught by the preaching of the priest , by their parents, by their surrounding culture etc. In fact, I think there is a quote in the New Testament that says “How else shall the people know about the faith without a preacher?” This is a paraphrase of course. A good preacher is VERY important. Even in our day and age where many of us are literate and have easy access to a ton of information regarding the faith
You don’t need to understand the words of the Mass to profit by it. The Mass is valuable in itself. It’s value and holiness doesn’t depend on whether people understand it or not. At least this is how I understand it. St Joan of Arc was a peasant of the first half of the 15th century in France. She stated in her trial that it was her mother who taught her the Ave, Paternoster, and I think the Gloria. Others in her village also remember her going to Mass and Confession a lot and tending to her sick neighbors. So clearly she knew something about her faith. Even if she, or other medieval peasants, couldn’t explain to you the technicalities of the Sacraments, of the Incarnation, or other things, doesn’t mean that their faith was void. As Thomas A Kempis teaches, faith isn’t about just knowing, it’s about believing and being virtuous.