Just a summary reminder in reading European history. (It probably works for all history.) Something you likely knew, but bears repeating because it is a different understanding than in our own day.
Medieval succession was not as formalized as it is with European monarchs in more recent times. It was not enough to have the most direct claim on
paper parchment of right to rule. Anyone hoping to become king had to have some sort of claim. But there were many complicating factors, and
any vulnerability would activate others who also had a claim of some sort. In
the imagination of moderns, there would be one rightful monarch according to
the rules, and all others are perceived as cheating in some way, trying to cut
in line. The use of the word “pretender”
illustrates this. To us, it means a
fake. In its time, it meant any claimant to an office who did not hold it.
If a respected king with a reign of some years died with a legitimate male heir who was of age, especially if he had shown some competence on his own, his claim would be difficult to dislodge, especially if he moved fast to either take over the treasury or get himself crowned. Speed sometimes mattered, and potential monarchs who were away warring for other interests sometimes had to choose what mattered more. Much could go wrong, even with the strongest claims. Legitimacy was less important in earlier centuries but was always a plus. Female monarchs were rare. Heirs who were still children might hold the throne under a regency, but in that instance an uncle, cousin, or brother-in-law might attempt to step in on his own. If we think of this as underhanded and unfair, it is worth remembering that this was always in the context of manipulative or warlike neighbors who might be able to take over the whole country if it did not have competent leadership. As that neighbor often had some claim of his own to part of the territory or the throne itself, the potential attacker might have ready allies within the kingdom already.
If you or one of your parents originally came from another kingdom, or even worse, spoke a different language, there might be enough popular sentiment against you that a younger half-bother, or another grandchild of a previous monarch would be preferred by many barons, dukes, and counts whose opinions mattered.
It was a relief when there was an orderly succession, but there was also some comfort in miserable times in dreaming of the rightful heir who might come across the water or over the mountain to be restored to his throne and bring just rule. The stories of various tasks and signs by which one might know the rightful king grow out of the misery of warfare when there was a problem of succession.
The stories of a prince who had accomplished some great quest being granted the hand of the princess and half the kingdom were likewise deeply satisfying to all stations of life, as it meant they had some hope of peace and competent government in the coming years. To those who had seen otherwise, it would still the nighttime fears of both adult and child.