I imagine that the answers to this question will largely be subjective, but I'll try to be thorough. My examples will be based on Pathfinder, since that's the system I know, but the spirit of my answer should be true for all RPGs.
You, as a GM, are only required to make the game fun for your players (I believe you're required to do your part in making a fun game. Otherwise, what's the point?). You do not have to cater to every design choice that your players choose to use. You don't ever have to have the party go up against Undead when you have an anti-Undead Cleric (a powerful but narrow build). You don't have to make every language the party takes relevant (relatively inconsequential). You don't have to put living, breathing NPCs up against your Smoke Bomb Ninja (a mediocre build that fails to gain any steam in a semi-optimal party).
It is the player's responsibility to understand that their build choices have an opportunity cost. The generalist will have limited answers in difficult situations that a specialist could trivialize or make doable. A specialist will fail to perform well under circumstances that do not fit their speciality. The Smoke Bomb Ninja is losing out on stealth-related ninja tricks or combat feats that could put their damage output into powerful ranges. The players should understand that the narrower their build is, the less effective they'll be in most situations. While every PC should have a certain level of general use to their kit, having a specialty or quirk in your build can be rewarding.
Some Anecdotes (and why I'm so fixated on Smoke Bomb Ninjas)
With all that said, you should take some opportunities throughout your game to make random knowledge or your player's specific builds shine, if only for a moment. It's a satisfying feeling to know that making a Smoke Bomb Ninja paid off in the exact moments you needed it to work. The Ninja in my party for Rise of the Runelords (a DnD 3.5/Pathfinder adventure path) never threw a single smoke bomb for their entire first 14 levels. It was book 6 (the last book) before they threw any smoke bombs. That book, they threw 2 smoke bombs. Each bomb shut down a mini-boss (2 different mini-bosses) that were threatening to overwhelm our party, a party that outright killed a 250 HP enemy at level 7 in one round (decently optimized Gunslinger/Inquisitor and a Holy Nuke Paladin with the charge that lets you pump your Lay on Hands as damage into an evil Smite target). That player was, in that moment, happier with how their character performed and more hyped about the game than any of us had been up until that point. Not only that, their build choice came into play exactly when the rest of us faltered.
My character (the Gunquisitor) was pretty satisfying to play throughout most of the game, but I had the most fun the one time I was forced into melee. I specced to have 14 STR instead of more CON or WIS, with the intention of randomly being able to fight in melee, well before I had plans to make them into an Inquisitor. My random melee ability allowed me to effectively fight a rogue that snuck past the party to attack me and used Step Up when I tried to 5 ft step back.
In our current campaign, my character got punished when he was the only person in the party that could read Elven and read inside a spellbook that said
"I prepared explosive runes today."
The trap was inconsequential, as it was a low level spell against our 12th level party and my character healed himself immediately and was in no danger otherwise, but it was a fun jab at his excellent literacy. I should also note that this has been a running joke between us for almost 2 years and never actually happened in game before now.
My best answer, while not directly an answer to your question, is to add in parts to your encounters and stories where narrow builds or build quirks matter. To your example about the Necromancer and the Bandits, why wouldn't you run the encounter like this? Diversifying your enemies makes for more rewarding encounters for the players (in a fun sense and for a diversity of loot sense). A supporty necromancer with Fighter Bandit leader and a few bandit goons and a couple skeletons/zombies can make for an interesting encounter, much more so than a handful of bandits. While you don't NEED a necromancer in the encounter, why wouldn't there be one?
If you can justify why you could include an enemy and it plays into a party member's strengths, then do it. If you can justify putting in a trap that only a certain party member can handle, do it. These make for feel-good moments for your players. If you're all having fun, that's what's important. I ask that you be more open and willing to modify your game just a little bit to create these moments. Sometimes, they'll be small. Other times, the table will jump for joy. These are the situations that make forum post stories.
Not all systems are created equal
Let's also consider another RPG, Second Darkness. Second Darkness, in my experience, is much better run in a manner agnostic to the builds of its PCs. In such a system, player-catering would indeed feel forced. Player satisfaction in being successful in encounters is much more based on player competency and use of their available tools than simply being allowed to use your tools.
This system is much more about creating plot points and allowing the players to figure out how to tackle them. The open-ended nature of the games it supports allows players to build however they want and to find places to make use of their abilities. No action needed by the GM.