Our Gemara describes an adulterous relationship that would lead to a wife becoming forbidden to her husband as one that is similar to ma’aseh she-hayah – “the event that took place.”
Rabbeinu Hananel writes that there was a long-standing tradition to identify this ma’aseh she-hayah with the story of King David and Bat-Sheva (see II Shmuel, chapters 11–12), and this tradition is accepted by all of the commentaries on the Gemara. They explain that, out of respect for King David, the story is referred to obliquely rather than in a straightforward manner.
The obvious question here, however, is that it appears from the story that Bat-Sheva becomes forbidden to neither her husband Uriah, nor to King David! By way of explanation, the Gemara brings a teaching of Rabbi Shmuel bar Naḥmani in the name of Rabbi Yonatan, which says that every soldier who went off to battle in King David’s army would first write a geṭ keritut – a divorce document – to his wife.
Rashi explains that these divorces were conditional; they were to take effect retroactively only if the soldier were to die in battle. The purpose of the divorce was to save the widow from the need to deal with issues of yibum or halitza. Although this appears to limit the effect of the divorce to a very narrow range of people, it is likely that we should understand Rashi as referring more broadly to any case where the soldier does not return at the end of the war, including situations where the soldier is captured or goes missing. This explanation, which is offered by the Ramban and Tosafot, would apply to any woman who would then be saved from being an aguna by means of this geṭ.