The rule for Nuns (and for Monks, and Bishops, and Cardinals, and Priests**) is that you can’t already be married and you can’t get married or have sex afterwards.
If you had sex in the past*** you can still join the Clergy. Some Nuns are widows, and others had sinful pasts that they since atoned for.
A big part of Christianity is God’s Forgiveness. The more sinful someone used to be, the more celebration there will be in Heaven when that person atones and repents.
** There are exceptions. Married Men can become Priests in the Eastern Rite, and Married Protestant Priests who convert to Catholicism can become Catholic Priests while still being married.
*** If you committed a sexual crime in the past, such as sexual assault, then you won’t be allowed in the clergy.