As others pointed out - a matter of law (and, in the real world, power politics). Most medieval and modern European monarchies would not have allowed it through much of their history, but in other parts of the world (and at other points in time in Europe) it was possible and even quite well known. A number of Roman emperors rose to the purple this way. As to today, I don't think it's provided for in most laws, but at least the Scandinavian monarchies would sort of be traditionally obligated to, given their rather meticulous attention to individual freedom.