That did depend a bit on edition and supplement.
I believe 1e stated all spells over 2nd or 3rd level were granted by a servant of the God, so they could withhold higher level spells from a priest who was out of line. Later 2e supplements went to the more classic "if your alignment shifts outside the allowed list for your deity, you lose all spells and granted powers". 3e walked that back, though I recall if you and your deity broke up, you lost your domains until you found a new deity (that might have been a house rule, it was a long time ago).
Of course, druids had it really bad with being absolutely Neutral, needing mistletoe harvested under a new moon or your spells weren't as effective, fighting other druids to gain name level and higher, oh and if you used non prescribed weapons or armor, you lost all you class features until you atone.
In fact, a lot of classes had weird restrictions, like rangers being Good, never owning more than they can carry (until name level) and never hiring henchmen or other helpers. Monks remained lawful and also fought to gain levels, as did assassins though the alignment was evil and "fight" isn't the word used to advance your career. Barbarians who started using magic items could become regular fighters, and thieves who became Lawful Good could no longer advance as thieves.
In fact, in 1e (and by extension in some cases, 2e) almost every class had some alignment or behavior based taboo that could kill your advancement or abilities in the class. The only exceptions were fighters and magic-users, though the latter often had to fear all manner of terrible things happening to their spellbook, lest their accumulated magic disappear to fire, flood, theft or book mites.
And believe me when I say there were DMs who knew and used every one of these tactics on their players...