This is nothing to do with grammar - it's a phonological phenomenon, and connected to the fact that pronunciation in English has changed much faster than spelling .
First of all, the -gh. In Middle English this was pronounced as a velar fricative - that's the sound spelt "ch" eg in the Scots word "loch" or the German "ich". It's phonemic symbol is /x/. However, gradually this either changed to a /f/ sound (eg
enough, cough, laugh, bought) or was dropped all together ( eg
though, through)
Then the vowels. If you take "through" - in Chaucer's time there was no standard spelling. It could be written
thurgh, thorgh throgh through thorogh thorough or
thurw. Gradually the written language became standardised and by Shakespeare's time "through" had settled to either
through or
thorough. During this time though, what is known as the Great Vowel Shift was happening - vowels were changing quality. How this happened is very complex -
this is an good site if you want the details.
But as I said, although the pronunciation of both the vowels and consonants changed, the written form didn't. And we've ended up with words whose written form actually reflects a much earlier pronunciation, which was radically different from the modern pronunciation.
So - nothing to do with grammar. The "rules" are phonological - but unfortunately they're those of the phonology of the 13th to 17th centuries