Wiktionary
bed trick
n. A plot device in Elizabethan and Jacobean theatre where a character begins sexual activity with someone else, then steals away after the lights are off, allowing another character to continue instead. The Guardian, 2013-05-16.
Wikipedia
Bed trick
The bed trick is a plot device in traditional literature and folklore; it involves a substitution of one partner in the sex act with a third person (in the words of Wendy Doniger, "going to bed with someone whom you mistake for someone else"). In the standard and most common form of the bed trick, a man goes to a sexual assignation with a certain woman, and without his knowledge that woman's place is taken by a substitute.