…she shall remain with him as a wife… (Deuteronomy 22:19)
A man could choose to marry a virgin or a non-virgin, though their dowries would be different. If a man marries a certain woman based on the assumption that she was a virgin and on the wedding night discovers otherwise, he has grounds to annul the marriage. (And, if she was unfaithful during the betrothal period, she would be guilty of adultery.) If, however, the court determines that the husband is lying, he loses the right to ever divorce her based upon his slanderous accusation.
The man presents his charges in the form of witnesses who claim to have seen the bride commit an act of adultery at a certain time and place. These witnesses might be refuted by a second pair, who say, “There’s no way you could have seen such a thing because you were with us somewhere else at that time.”
The reason for this mitzvah is pretty obvious: it’s a disincentive to falsely filing such charges. If a groom wants to get rid of his bride quickly and without having to pay the value of her kesubah, he’ll think twice. If he attempts such a reprehensible plot and is found out, he’ll never be able to divorce her at all. The possibility of such a plan backfiring and blowing up in his face should encourage a disgruntled groom to deal with his problems properly.
Oh, yeah – if the groom is found to be lying, he’s also whipped, as per Deuteronomy 22:18, and he pays a fine. Since the girl in question is a naarah – a minor – the fine is paid to the father.
The fine and the whiplashes are only imposed at a time when the courts have the authority to administer such punishments. The obligation to retain the girl he has slandered applies in all times and places.
This mitzvah is discussed in the Talmud in tractate Sanhedrin on pages 8a-9b and in Kesubos on pages 44a-46b. It is codified in the Mishneh Torah in the third chapter of Hilchos Naarah Besulah. This mitzvah is #219 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos; it is not listed in the Sefer HaMitzvos HaKatzar of the Chofetz Chaim.