The real solution is to force these kingdoms to build permanently open gates and roadways that connect the land, increase all around traffic and opportunity.
Only when people turn from digital vassals to digital citizens will we emerge from the middle ages we are currently in. In this sense the most important development in the online world is still ahead if us.
I don't think any of these castles were built directly by kings - although I suspect their construction was either approved by a king or by someone who had delegated authority from a king. NB I can also see a large castle about ~11 km away that was a royal castle (and still has a military garrison).
I suspect that most castles are probably in other people's kingdoms.
In practice, unhappy nobles would often rather deny their necessary cooperation (at war or administering the land in peace) and thus force the king to make some amends and tradeoffs.
Passive aggressivity isn't a modern concept :)
Well, there is the practical purpose of legitimacy. It may seem too soft for modern power theoreticians, but the legitimate king has something that cannot be acquired by raw power, and that puts somewhat of a damper on potential rebels. Not on each and every one of them, of course, but it has a wide effect. Killing or deposing the legitimate monarch was a serious spiritual crime for which one could pay not just by his earthly life, but in the afterlife as well.
Even usurpers like William the Conqueror tried to obtain some legitimacy by concocting stories why they and nobody else should be kings.
We still see some reverbations of that principle today. Many authoritarians love to "roleplay elections", even though they likely could do it like Eritrea and just not hold any. It gives them a veneer of legitimacy.