You've already stated the key point:
1 reaction, which you take when you are hit by an attack or targeted by the magic missile spell.
So what you need to understand here is that the Shield spell involves time travel. No, really, it does. You can cast Shield when you're hit by an attack. Not when you're targeted, or when someone tries to attack you, but when you're hit.
The time travel shenanigans comes into play because the AC bonus of Shield applies to the attack that caused you to cast it. So stealth doesn't apply here, because when the Rogue stabbed the Wizard, it gave away his position. Then the Wizard changed history with the Shield spell.
See here for a similar explanation phrased a little differently. It's easy to understand how this works in terms of gameplay: wizard gets hit, wizard casts Shield, wizard does or doesn't get hit based on his new AC including Shield. How it works in-game is, well, magic! (Alternatively, if you prefer, A Wizard Did It.)
Can you dispel a magic effect you can't perceive?
Yes, as long as you can locate it somehow. If you can't find it somehow, then no. This reduces down to the related question: Can you target a target that you can't perceive? And the answer to that is a qualified yes. Yes, if you can land your dispel magic on the desired target somehow.
As we'll see, your example situations don't allow you cast the spell yet, because you haven't targeted anything. But first, let's look more at how targeting works.
Targeting spells
To target something, you need two things per Targets on PHB page 204 (unless the spell's own description lifts one of these, or adds new requirements):
The ability to choose the target
A typical spell requires you to pick one or more targets to be affected by the spell's magic.
And dispel magic does require the ability to pick the individual target:
Choose one creature, object, or magical effect within range
A clear path to the target
To target something, you must have a clear path to it, so it can't be behind total cover.
This isn't a problem in either situation you're asking about.
So in order to target something, you need to be able to individually choose it. To be able to do that, you need to know that it's there and where specifically it is. You often gain that information by sight, but sight is not required, only knowing the location of your target is required. This information can be gained by many other means: hearing, touch, divination magic, etc.
Now, about that qualified “yes” above: can you target something you can't perceive at all? Only if you have enough knowledge from something other than perception in order to correctly target it.
For example, if a god granted you divine intervention and whispered in your ear to say “the invisible wizard is hiding behind the third barrel in the south-east corner!”, then you'd be able to target that invisible wizard without needing to use a perception ability of your own. This choice would be “I target the invisible wizard right there, behind that barrel.”
As another example, if you had a note from a wizard that said, “cast dispel magic on the centre of the wall between the 11th and 12th statues on the left of the entry hallway of the Grand Palace”, that's enough knowledge to correctly target your spell at the illusion the wizard put in that exact location and reveal the secret door (or whatever is there). This choice would be “I stand in front of the wall between the two statues, and I target the magical effect that is right in front of me.”
Other than unusual help like that though, you generally need to be able to locate your desired target, which will almost always require some kind of perception on your part. We can't literally require “perception” in all cases though, because being too literal about that though would rule out some cases like the above where you obviously know enough to target the spell correctly — and we don't want that. D&D 5e is, after all, supposed to be sensible rather than literal-but-counter-intuitive.
The examples in the question lack targets… so far
So you could target something you can't see, but in the examples, no targets can be selected yet without changing the situation somehow.
Notably, you can't just choose a general type of magical effect and hope it is somewhere in range, because that's not targeting an individual magical effect. Dispel magic is not an area of effect spell! Just like you can't choose a magic missile at “any orcs in the room”, you can't dispel magic “any invisibility effects in the room”. You have to be able to pick a specific target and cast your spell at that target specifically.
That means that in both your examples, you can't just cast the spell at nothing, say “Invisibility, I choose you!”, and have dispel magic find the invisibility effect and dispel them just because it's within range. You didn't pick your target! Instead, in each situation, you have to do some more work to acquire and choose your target:
You have to locate the invisible hiding evil wizard somehow; most likely by using Perception checks (but divine intervention would work too). Once you positively acquire the knowledge of the position of the evil wizard, then they can be targeted by dispel magic.
You can't can't dispel magic on “any and all invisibility effects in range” because that's not how targeting works — that's not one, as dispel magic requires, that's multiple. You would have to pick one instance of an invisibility effect somewhere specific in the room:
- Try to detect the presence of invisible things in the room somehow,
- Then, if there are any, locate one of them specifically somehow,
- Then target dispel magic at that one magical effect specifically.
Anything else isn't targeting, it's throwing a spell into the wind and hoping it magically does something its description doesn't say it does.
Best Answer
Yes you could dispel it, but the initial attack would still miss
The DMG has guidance on when Readied actions (and reactions and triggers in general) occur:
Your dispel magic spell could certainly remove the shield spell from a target (so they wouldn't have a +5 to AC for the rest of the round): but it could only do so after the shield spell had been successfully cast. And the casting of the shield spell will disrupt the initial attack which triggered it.
If you want to stop the Shield spell from taking effect at all, use counterspell, not dispel magic, as suggested in the Sage Advice Compendium, p. 15 (which also wouldn't require you to Ready a spell, spending both an action and a spell slot before you're sure your enemy even intends to cast a spell).