That night he dreamed. A duel between magicians makes a fascinating tale. Such tales are common—and rarely true. The winner of such a duel is not likely to give up trade secrets. The loser is dead, at the very least. Novices in sorcery are constantly amazed at how much preparation goes into a duel, and how little action. The duel with the Hill Magician started with a dream, the night after the Warlock's speech made that duel inevitable. It ended thirty years later. .... And in his sleep he concentrated, memorizing details. A narrow path curled up the hillside. Facts twisted, dreamlike. There was a companion with him; or there wasn't. The Warlock lived until he passed through the gate; or he died at the gate, in agony, with great ivory teeth grinding together through his rib cage. He woke himself up trying to sort it out. The shadowy companion was necessary, at least as far as the gate. Beyond the enemy's gate he could see nothing. A Warlock's Wheel must have been used there, to block his magic so thoroughly. Poetic justice? He spent three full days working spells to block the Hill Magician's prescient sense. During that time his own sleep was dreamless. The other's magic was as effective as his own.
Larry Niven's novelette "What Good is a Glass Dagger" isn't generally super well remembered; to the extent people think of it, it's in relation to the much more famous sequel, "The Magic Goes Away", which used magic as a metaphor for the oil and energy crisis.
(It's also one of the first stories to use the word "mana" to refer to magic power; it's still exotic enough that Niven italicizes it in the text. It's not the first ever, but I believe it's the actual source that RPGs drew on when they used that word.)
But this passage has always stuck with me. Wizard duels aren't flashy explosions of power. They're very careful maneuvering, with decades of prescience, and the winner is the one who best manages that careful maneuvering around their opponent's blind spots while creating blind spots for their opponent.
(There's a truism in D&D3.x that a level 13 wizard, with time to prepare, can kill anything that isn't preparing in return. And I feel like this story represents that concept really well, though the details are all different.)
the-world-annealing Why level 13 specifically? Simulacrum?
I don't know that it was any one specific spell; at that point you have most important options unlocked. I think the big one is the Greater Teleport and Greater Scrying combo, which unlocks scry-and-die; but you also get Banishment, Simulacrum, and Limited Wish, and these all stack on top of Contingency, True Seeing, and Planar Binding, which unlock at level 11.
But scry-and-die is just very broken because D&D 3.x has a ton of powerful round/level buffs. So you can't possibly stay fully buffed as like a regular thing; but if you can dictate encounter timing you can go in fully buffed, while your opponent isn't. So you cast, like, six round/level buffs, then on round seven you cast Greater Scrying to locate your enemy; on round eight you cast Greater Teleport to show up in his room; then you have rounds eight through twelve to murder the shit out of him while he's basically unprotected, and on round thirteen you leave.
And no, in the written rules there are very few countermeasures here. A Mind Blank makes you immune to scrying, but if there's anywhere you're going to predictably be that doesn't help that much. (That said, a high-level wizard who lives alone in a wizard tower under continual mind blank is relatively safe, until you find a way to locate them.)
If you want to lock down an area, Dimensional Lock will prevent travel for one day/level, but it's an eighth-level spell and it covers a 20-foot radius. So a level 20 wizard gets six casts a day, unless they're really abusing stat bonuses in which case they get seven. If you devote all your arcane power to just casting Dimensional Lock, you can lock down 20 times seven 20-foot radii at a time; if we're generous and use the taxicab norm so this is a 40x40 square, this covers about 200k square feet, or about nine thousand squares, or a 90-square radius. And this can in fact lock down a castle pretty well, but notice this is using the entire eighth-level spell array of a 20th-level wizard, so it represents a huge investment of resources. And even then, you just have to wait for them to leave their fortress once while you're scrying them.