I think the real question should be how many classes should be in the core rules vs how many classes there should be total. Personally speaking, I don't mind a huge amount of classes being available as options, but do favor a DM limiting access to fit the particular needs and styles of their campaign.
Overall, I think that 10 to 12 total classes is a good sweet spot. Perhaps 6-8 for lighter clones and spinoffs, and 3-4 for those old-school minimalist systems. For the Fighter/Thief/Magic-User/Cleric being the baseline, 10 to 12 has just enough variation for things to fit into the four archetypes.
Fighter: Barbarian, Fighter
Thief: Thief/Rogue
Cleric: Cleric, Druid
Magic-User: Sorcerer, Warlock, Wizard
Hybrids: Bard, Monk, Paladin, Ranger
The above covers just about each of what's in 5e today. For pre-WotC systems one could swap out the Warlock for an Assassin. Or a Warlord for 4e.
I recall reading in an issue of Carcass Crawler (Old-School Essentials' official zine) something that resonated with me in regards to how many classes are too many:
One approach that works well is for the referee to select a limited set of classes (say between 7–10 in number) that are available in the campaign. For example, in one campaign, the acolyte class may replace the cleric.”
“In this way, the number of choices available to players when creating characters is kept within reasonable bounds, while the hand-picked set of allowed classes can heavily reinforce the flavour of the specific campaign.
In looking through various classes published both officially and for various D&D retroclones, I was able to come up with some tightly-themed campaign styles just by what's available. For instance, here's a sample array I made for an OSR Folktale Fairy Setting:
1. Beast Master (Carcass Crawler)
2. Changeling (Carcass Crawler)
3. Druid
4. Elf
5. Fairy
(Reddit Homebrew)
6. Fighter
7. Gnome
8. Thief
9. Warden (Carcass Crawler)
10. Witch (Oh My Lost Darklords)
I kept the Fighter and Thief, but ditched the Cleric and Magic-User in favor of more specialized types of casters. The Druid fits with one relying upon the powers of nature, while the Elf and Gnome both have spells drawn from Magic-User/Illusionists but have their own distinct playstyles to make them feel different. The Warden is a variant Ranger, and the Witch is a folkloric arcane caster that favors more subtle magic. The Beast Master is all about befriending animals to fight alongside them, while the Changeling plays into the "face-stealer fey" archetype.