NPCs can use different rules than PCs in 5e
It is true that in 5e, a PC wizard can pick 2 spells each time they gain a level from the overall wizard spell list, so once they get to 9th level, there is no stopping them from picking wish. However, NPCs do not need to follow the same rules as PCs when being built. The DMG says under Designing NPCs (p. 92):
When you give an NPC game statistics, you have three main options: giving the NPC only the few statistics it needs, give the NPC a monster stat block, or give the NPC a class and levels.
So technically, you can design that NPC without elaborating how they got their spells. Why does the Lich not have Wish as its level 9 spell? Why does the Archmage not have Wish as their level 9 spell? Both of them can cast level 9 spells, both of them are official monsters, and the Archmage is without doubt the monster-stat-block version of a high-level NPC wizard. You can easily point to precendent, we don't ask for a justification for those, either.
NPCs are build with story and personality in mind first, and with min-maxing, maybe second. As are many PCs -- not everyone is a min-maxer.
Wish is not the only viable option
A second aspect is that your question implicitly assumes that wish is the best of all the level 9 spells by such a wide margin that there is no competition as to what to pick -- you would always pick it. That both assumes that the wizard is purely about maximizing power, rather than pursuing his interests, and that wish in fact is the best when it comes to power.
And while I agree that Wish is a great spell, and probably the overall best and most versatile level 9 spell for wizards, there are other great spell options on level 9. These options do not run the risk of losing them forever when you use them to achieve an effect you cannot get from a level 8 spell. They are entirely defensible picks, even for a PC wizard. Foresight might beat it for sheer everyday effectiveness. True Polymorph can create all kinds of shenaningans by getting around creature type restrictions of other spells. Meteor Swarm is the king of big area damage.
And if you allow for the wizard having chosen their spells following their interest, for an illusion wizard, Weird (probably the most sucky of all the options) is a pick from their dedicated School of interest.