It's mostly up to the DM, but Xanathar's Guide to Everything has some optional rules
In Xanathar's, Chapter 2 has a Spellcasting section that begins with:
This section expands on the spellcasting rules presented in the Player’s Handbook and the Dungeon Master’s Guide, providing clarifications and new options.
That's a little unclear as to what's a clarification vs what's a new option, but given that identifying spells isn't covered at all in the PHB or DMG, then I tend to view identification of spells as an option rather than a clarification.
Identifying a Spell states (my emphasis):
Sometimes a character wants to identify a spell that someone else is casting or that was already cast. To do so, a character can use their reaction to identify a spell as it’s being cast, or they can use an action on their turn to identify a spell by its effect after it is cast.
The specifics for how this works are listed in the book, but I'm honestly not a big fan of it because of the action cost listed above.
This is especially true for counterspell which already uses up your reaction. So if you use your reaction as stated above, then you won't be able to actual counterspell, which is pretty unsatisfactory from a player's perspective.
How we've done it at my tables
At my tables, we've tried a couple different options with varying effect. I'm not sure which I like more, so I'm going to just go ahead and discuss what we've done and let others determine if they prefer one of the ones I've used or the Xanathar's method.
You've gotta guess
In this scenario, there is no way to identify in time. You are perceiving a caster at work and throw up a counterspell to stop them. It's up to the player to determine the level of the counterspell they want to use, and they take the risk of wasting it against a cantrip or requiring an ability check if it's higher than the spell slot level they've used.
Honestly, I kind of liked this one the best. It gave you a choice to make, and one with cost. It's an in-the-moment event and if you feel that the risk was worth the reward, then you go with it.
Cost-free identification
We tried allowing an Arcana check at no cost. Similar to the system in Xanathar's, but without the reaction cost. This gave the player's more info and the ability to decide if and when to counterspell.
What's kind of nice about this is that it does create a bit more of a level playing field between PC counterspellers and NPCs. Looking at the flip side, most player's don't begin their action with "I'm casting a generic spell", they tend to state the spell they're casting. This gives the DM info that they don't necessarily provide to the players in the same way.
Being able to know each and every spell cast as it's being cast seems a bit more fair, but it also removes a lot of the potential risk.
This option is perfectly fine as well, but I did kind of like the unknown risk of my first option.
What about working as a team?
Another potential option is have two players work together. One player uses their reaction to identify, and then once identified, the 2nd casts counterspell with the additional information.
And that type of action is also going to be table dependent. This question covers some of the issues revolving around speaking outside of your turn (during a reaction in this case.)
It comes back to being up to the DM/table to decide
Whether you use the method from Xanathar's (whether optional or 'actual') or one of the systems I've tried, it's all about having fun. What works for one table and everyone enjoys it won't necessarily be the same for another table.
Talk to your group and figure out what method works. If you don't like how it ends up, you can always change it after talking about it.
To sum up the mechanics of counterspell:
If a creature with counterspell available can perceive any spell within range being cast, they can attempt to counter it. They don't need to know what spell it is, or even have it on their class list to make the counter. Based on this, and what I gather from your context, the short answer is: yes the NPC could have cast counterspell.
Let's tackle the issues one at a time with this knowledge:
Issue 1:
The NPC doesn't have to know that a silence spell is being cast. All they need to know is that a spell is being cast at all. Counterspell counters any spell after all. How would they know that a spell is being cast? Because silence has verbal and somatic components. So, as long as the NPC can see or hear the caster casting something, the NPC has the option to counterspell it.
Issue 2:
Yes. It's been established in the Sage Advice Compendium that (emphasis mine):
If a spell that’s altered by Subtle Spell has no material component, then it’s impossible for anyone to perceive the spell being cast. So, since you can’t see the casting, counterspell is of no use.
So, if the NPC can't perceive the spell being cast, then they can't counterspell it. In most circumstances (casting during combat or from a different room) it's up to the DM to determine if the NPC can perceive the casting. But if the DM rules (or is convinced) that the NPC can't perceive the casting, then the NPC can't counterspell. In this case, I assume that the NPC could see you casting, and you were within range, so counterspell would have been a legal reaction.
Issue 3:
It could, though it doesn't have to. There are some optional rules that allow creatures to identify a spell as it's being cast, but those are... well... optional. Unfortunately, the DM just has to make a call on what this particular NPC would do, and stick to it. There is no rule pulling the decision one way or another. It's reasonable for the DM to rule that the NPC would take the risk and not counterspell whatever you decide to cast. But, it's just as reasonable for them to rule that the NPC would assume that any spell you cast is a threat that can't be allowed to pass, and so would counterspell it regardless of what it turned out to be.
Issue 4:
Technically, a creature doesn't automatically know anything about the effect of whatever spell a different creature is in the process of casting. But the rules are, again, silent on this matter beyond that. So, if the group decided that minimizing metagaming is something that they want to strive for, neither they, nor the DM should know what spell is cast before deciding to counterspell. But that is a conversation that you all will need to have as a group. Some groups are more lenient where everyone knows what spells are being flung around. And still others let the players know what the enemies cast, but not the other way around. You all have to decide for yourselves what would be the most fun.
Best Answer
It's at the very least more fair than you think it is.
The check for the counterspell is an ability check of the type of your spell casting stat.
This means that the maximum bonus a character can get (unless they are a bard with Jack of All Trades), is +5. Bards being the rare exception get half proficiency to all checks they aren't proficient in already and thus can get up to +8 at 17th level.
Since you're at least 5th level, we can assume your casting stat is between 18 and 20 (it may be 16 if you took a feat or MCed a couple of levels, and it might be 14 if other circumstances are true), so we'll use 18 here.
This means that the modifier to the check is +4, meaning that to counter a 9th level spell, you need to roll at least a 15 meaning only a 30% chance of success. Sure this sounds like a lot, but in reality, a 30% chance isn't all that much.
The abjurer, at L10 does have a feature that will add their full proficiency to counterspell checks. However, since this is a pretty significant class feature (This is the same level the evocation wiz gets to add their int to all their damage), it's not out of line by any stretch.
Addendum: Though this isn't part of your question, this is a particularly nasty spell for an NPC to use on a group of PCs, and one that a DM should consider with caution. Counterspelling a fireball is fine, counterspelling the party's last-minute emergency teleport that was meant to prevent a TPK probably isn't. (HT to Miniman and BESW)