Disclaimers: I have no linguistic knowledge whatsoever, I'm just fascinated by these subjects. Also, I will use the word "dialect" due to my lack of a better word, although I see that the description of the "dialects" tag talks about "mutually intelligible" while the things I'm talking about don't need to be mutually intelligible and in fact are often not. I hope someone can correct my use of the word "dialect" with the right word, but this is not my question, just a premise.
The context I have in mind is Italy, where we have a national language taught in school and a myriad of very localized dialects, which are full-blown languages with their syntax, pronunciation, rules etc. and which are often almost unintelligible by speakers of other dialects and by Italian-only speakers. But I'm sure the same phenomenon exists in many countries so my question is not specific to Italy at all.
Up until a few decades ago, most of these dialect speakers, especially the older persons and especially in the countryside, barely went to elementary school.
Most of these dialect speakers make a significant amount of errors when they speak Italian, but they speak their dialect basically without any errors at all. In the same geographical area these speakers all strictly comply with the same language rules and their compliance is very consistent among the population and the level of this compliance is certainly not inferior (and maybe superior) to the level of compliance of the average urban Italian high-school graduate speaking Italian.
What puzzles me is that their dialect was not taught to them in school (where most likely it was rather discouraged and mocked) and I doubt that people in their community taught them the rules of the dialect. I believe that the children just learn it by being raised where it is commonly spoken.
This clashes with my long-held idea that in order to learn to speak a language - even one's native language - with perfect compliance with the rules, one must have had the rules taught to him/her, while this doesn't happen for these dialect speakers, they don't have the rules taught by others.
I would expect that if one learns a language just by growing up where it's spoken, without being taught any rules, of course one would learn it (especially if one starts as a child) but this would result in a general sloppiness regarding compliance with the rules among the speakers, or even result in a scarcity of actual rules. Instead no: precise rules, full compliance, hardly an error.
So how does this aspect of languages work ? How can these dialect speakers consistently get the rules of their dialect perfectly right without having ever studied those rules ? Of course they learned that by being born and raised in a community that speaks that dialect, but why in order to get the same level of compliance with the rules in the national language we need to study it for good and still many of us hardly get as perfect at it as those dialect speakers are all perfect at their dialect ?