580. Swingers: The prohibition against remarrying an ex-wife who married someone else in the interim
Her first husband, who divorced her, may not take her again as a wife… (Deuteronomy 24:4)
If a couple gets divorced, they are allowed to get remarried (assuming that the husband is not a kohein, since a kohein may not marry a divorcee, including his own). However, if a woman married someone else in the interim, she may not remarry her previous husband.
The reason for this mitzvah is to serve as a barrier to immorality. How so? It’s pretty clear once you think about it. Let's say that Mary is married to Joe and Sally is married to Bob. These couples get divorced so that Mary can marry Bob and Sally can marry Joe. After six months or a week or a one-night stand, the new couples get divorced and remarry their original spouses. Boom–you’ve found a loophole for "wife swapping" within the context of marriage. But God thought of that before any human, so He blocked it by prohibiting one from remarrying his ex-wife in such a case.
While the language of the verse primarily addresses the husband, the mitzvah applies to some degree to both partners–after all, he can't do it alone! (This mitzvah only applies if the wife married somene else; if only the husband had been married in the interim, it's another story. This is because, under Torah law, a man might have two wives. A woman never has two husbands.)
This mitzvah applies in all times and places. It is discussed in the Talmud in tractate Yevamos on pages 11b-12a. It is codified in the Shulchan Aruch in Even Ha’Ezer 10. This mitzvah is #356 of the 365 negative mitzvos in the Rambam’s Sefer HaMitzvos and #134 of the 194 negative mitzvos that can be observed today as listed in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar.