In a perfect world where the GM had infinite time, they could keep track of all the moving parts as they are happening. Let's say that dungeon held McGuffin #3, which the PCs were told about but chose to ignore in favor of Personal Goal #7. The GM knows that Duke Dingleheart wants McGuffin #3, so since the PCs don't offer to get it, he sends Rival Adventuring party Q after it. The GM makes a couple rolls and establishes that the NPC party succeeds after 3 weeks, losing 2 members. If the PCs don't change course or do something else to influence these events, this is the new status quo. This may hve downstream effects, including Mistress Magika now coveting McGuffin #3 and trying to hire the PCs to steal it, or whatever.If you prep something and the PCs do not go there, and then several levels later they choose to go there, should it be the same dungeon? Or, should it now be swapped out with bigger monsters to be challenging to the higher level PCs?
There is a couple ideas I would have if this happens. I might make a set of NPCs that already went there and cleared it out. I might have it remain the same and the PCs have not problem and just overpower the monsters. I might replace the monsters with something since the game evolves along with the PCs. Maybe the goblins, or whatever, were taken over by trolls who now live there.
The point is, it does not have to be static if the GM wants time to move forward. This has the benefit of telling the players that their characters exist in a "living world" and the choices they make, including not choosing, will have impacts and consequences.
But, again, that is a perfect world. I might think up some of that stuff when the PCs finally wander into the dungeon hex. Or I might just let them encounter it as is. I don't think I would swap out a more level appropriate dungeon that still fits the evidence, rumors, etc... that led the PCs there. Probably. At the same time, if we are itching to play and this is all I have ready and it doesn't break anything, I might do it anyway. That isn't the right answer and it isn't really how a sandbox should be run, but from a practical "let's spend our gaming time on something actually engaging and fun" perspective, it would probably be okay.
"Shoulds" and "theory" can get bent sometimes when fun is on the line.