Oofta
Legend
But isn't that is exactly the question? Probably the best test would be to have a group of players charged with defending a site and seeing what they come up. Because they are players they are limited to published spells and items. So "anti-invisibility" areas aren't something possible in the rules, but hallowed areas would be. Give them a budget and see what kind of defenses they can build. In my opinion, to build defenses to handle the types of threats represented in a normal game world is going to be cost prohibitive compared to the methods that are necessary to defeat them.
This is probably why they haven't released the mass combat rules yet. It would be interesting to try and build a "tower defense" game just using the published rules to this point. But I don't think the rules are really robust enough to handle this situation. Back in AD&D we did run similar types of tests and found that castles were generally useless against monstrous and magical threats.
How much flexibility do you give them? Can they "invent" weapons like my net throwing ballista? Create new rituals? Special wards against specific types of magic?
The way I run it the printed rules aren't all inclusive, they include rules for PCs. But it's going to vary widely by campaign and preference. I warn people that they may not be able to teleport wherever they want, that some walls may be warded against spells that bypass them.
Unless magic is new or extremely rare there will always be some sort of countermeasure built over time. The romans used what we would consider short swords until they started fighting enemies that used cavalry and they started carrying spears. Armor slowly got to the point where stabbing someone didn't do a lot of good so people switched to knocking them down or focusing on bludgeoning them to death or having a lot of power focused on a very small point. Then firearms came along and armor fell out of style because it wasn't worth the cost until fairly recently (for most soldiers anyway, there have always been exceptions).
My point is that magic wouldn't be "disruptive" unless it was only introduced recently.
Ultimately though most people just accept some things about D&D that don't really make a lot of sense. Yes, there are orcish hordes, but where do they come from? From the mountains? Okay, what did they grow to eat? How are there viable populations of dozens of different intelligent humanoid races, especially if they're constantly trying to kill each other off?
How much any of that matters, or how much it affects your particular taste is going vary pretty dramatically from campaign to campaign. I try to keep things logical, but I also just hand-wave some details. I want castles so I assume they're worth building. I'll come up with details of why when and if it matters.