Laundry List;
There's a nice spell somewhere... SpC? That allows you to present a false image to would-be scryers. Direct all scry-and-die-ers to your trap-room.
Forbiddance most of the castle.
Use Greater Anticipate Teleportation if the king needs to be moved (Forbidden City etc analogues would exist a lot more in DnD... actually moving a ruler is a huge security risk), as well as extensive scrying to anticipate attempts on the king's life.
Contingency is your friend. Divert Teleport is a psionic power that you might get some use out of.
Have a monster or golem with a Burrow speed to serve as a 'panic room' for the king that leads to the underground high security bunker. Have built in communications in the golem/monster.
Readied actions. Even if you don't have your Mage-Slayer chain using death jester assassins Readied at all times of the day and night, if you get some kind of warning, even a a Splitting Swift Hunter behind a lead sniper's window in the throne room can make a difference.
Line of Effect/Sight. Walls of Force/stone/anything, especially contingent or trap versions, can end an abortive attack before they begin. For bonus points, have your castle's stone walls reinforced by forcewalls so Gate-Lava from above won't destroy it. For extra bonus points, have walls + illusions, so the king is literally 'in another castle'.
If possible, have king literally be another person than the guy sitting on the throne. So if the guy on the throne gets scragged, it's a PR problem, but not a disaster.
In the psionic tricks thread, there's the reset button trick - you time hop a psycrystal (or something) with the spell that lets you reset CL rounds back in your personal timeline if you want 24 hours into the future. If the king gets killed, record a message for your 24 hours past self, and then reset time.
For the security-conscious monarch, nested demiplanes is a very solid defensive move.
Encase the king in a him-shaped astral construct that does nothing but block LoE and LoS to him(note: King must have a way to breathe).
Something lots of people forget is that with a spellguard of silverymoon, you can persist all the usual wizard defences onto someone else. Even without a spellguard, touch spells can be persisted, so a king can be immune to metal weapons, rays, magic, poison, disease, attacks with a bonus of less than +60, plants, living creatures, undead, constructs, spells of lower than 8th level, magic that doesn't work in an antimagic field, and gophers.