This was particularly common in the Frankish kingdoms, though it happened elsewhere too. Some important personage, usually but not always the king, would give a monastery to a friend, a wife, or a person they wished to reward. Charles Martel, Mayor of the Palace to the Merovingian kings and grandfather of Charlemagne, was supposedly the first to do this. Many subsequent kings continued this practice even while supporting the very reformers who called for an end to it.*
Queens and king’s daughters were common recipients of such honors, as were princess’s husbands. Charlemagne made his friend Angilbert, who was also his daughter Bertha’s lover, abbot of St. Riquier. After his death, the post of abbot was given to other laymen. Gisla, daughter of Lothar II received charge of monasteries of Nivelles and Fosses (a male monastery).** Richardis, wife of Charles the Fat, was variously the lay abbess of monasteries at Säckingen, Zurich, and possibly Andlau.
The Church as an institution was, unsurprisingly, not happy with this way of doing things. The general claim was that lay abbots and abbesses led their monasteries into decay and degeneracy. Given both the general lack of any close relationship between the lay abbot/abbess and the community and the usual lack of interest in monastic life on the part of said lay abbot/abbess, this is unsurprising. (It is worth pointing out, however, that both Richardis and Agilbert (discussed above) are now considered saints.) Several synods and church councils over the centuries condemned the practice, but it wasn’t until the Investiture Controversy*** came to a head in the 11th and early 12th centuries that the practice was ended and only people who had taken vows were allowed to become abbots and abbesses.
*The Rule of St. Benedict, for example, states explicitly that the abbot of a monastery should be elected by the members of the community. It gives no option for appointment by an outsider. Charlemagne had no qualms appointing people as lay abbots and abbesses while working to spread the use of this particular Rule.
**As far as I can tell, it was highly unusual for a woman to be given a male monastery or vice versa, but it apparently happened at least this once.
***Way oversimplified, this was a “No, me!” fight between secular rulers and the Church over who got to appoint the bishops.