Has any monk or nun in Church history ever left a monastery to be married to a king or queen?
Her parents afterwards obtained a Papal dispensation in order to marry her to the King of Bohemia, but this only gave Margaret an opportunity of showing that her religious life was the result of her own free choice, for no prayers or entreaties would induce her to quit the cloister.
Addressing the question of whether it is expedient to marry, Fr. Thomas Crean, O.P., writes:
There could also be other reasons why it could be expedient for him to marry, for example, if some great good of a spiritual nature would result for a multitude, for example, woman who foresees that she would convert her pagan husband who is a very powerful man, such as a king, or some other man of great power.
Despite the common good being greater than an individual's good, St. Thomas Aquinas argues that an individual religious person (monk or nun) cannot be called back to the world, no matter the human good that may result (II-II q. 88 a. 11 "Whether it is possible to be dispensed from a solemn vow of continency?" arg./ad 1; Freddoso transl. PDF pp. 2395,7):
[arg. 1:] one reason for granting a dispensation in the case of a vow is that the vow impedes a greater good. But a vow of continence, even if it is a solemn vow, can be an obstacle to a greater good, since the common good is more godlike than is the good of a single individual. But someone’s continence can impede the good of the whole multitude, e.g., when the peace of the fatherland could be secured through a contract of marriage between persons who have vowed continence. Therefore, it seems that a dispensation can be granted in the case of a solemn vow of continence.
Una enim ratio dispensandi in voto est si sit impeditivum melioris boni, sicut dictum est. Sed votum continentiae, etiam si sit solemne, potest esse impeditivum melioris boni, nam bonum commune est divinius quam bonum unius; potest autem per continentiam alicuius impediri bonum totius multitudinis, puta si quando per contractum matrimonii aliquarum personarum quae continentiam voverunt, posset pax patriae procurari. Ergo videtur quod in solemni voto continentiae possit dispensari.
[ad 1:] The dangers associated with human things should by obviated by means of human things and not by means of divine things being turned to human use. But those who have professed the religious state are dead to the world and life for God. Hence, they are not to be called back to human life by reason of any turn of events whatsoever.
Ad primum ergo dicendum quod periculis rerum humanarum est obviandum per res humanas, non autem per hoc quod res divinae convertantur in usum humanum. Professi autem religionem mortui sunt mundo et vivunt Deo. Unde non sunt revocandi ad vitam humanam occasione cuiuscumque eventus.
My question here is sort of the converse of: "Are Catholics allowed to leave marriage in order to become a monk or nun?"
Religious like Pope St. Celestine V have been recalled from their monasteries to become bishops—though the episcopal state is a more perfect state than the religious state, because "bishops are in the position of 'perfecters'" of others, which is a greater thing than those (religious) who "are in the position of being 'perfected'" (e.g., as a teacher is greater than his students or a general than his soldiers).