Linguists use the term grammar differently from most English teachers. To a linguist, “grammar” refers to the rules that speakers unconsciously follow when they put together strings of words to create sentences.
These rules aren’t learned in school; instead, speakers learn them by instinctively picking out patterns they hear when they’re growing up. Just as every language has its own grammatical rules, every dialect has its own rules, too. When linguists say that a phrase or sentence is “grammatical” in a dialect or language, it means that most speakers of that dialect or language would agree that that phrase or sentence sounds correct or is commonly heard.
For example, in some dialects of English in the US South, it is grammatical to use might could in a sentence— but only if used correctly! One of the “rules” for using might could seems to be that it can’t be used when talking about something that has already happened. So, a speaker can say I might could go to the store tomorrow. but not I might could go to the store yesterday. Although might could is ungrammatical for many speakers of English (in other words, it sounds weird), it is perfectly grammatical for the speakers who have it as part of their dialect.