Acting.
Even on a closed set, there’s still quite a few people working near the actors. No one is unaware that they’re at work, you know? And they’re wearing flesh-colored pasties on the lower bits, usually. Now, after the scene’s in the can, all bets are off in the stars’ trailers!
Edited to add: These scenes are choreographed between the camera, lighting and the actors to pull off the illusion. And they take a lot of time to set up. If you had to contort yourself the way actors have to, you’d be very sore. And people do sometimes get aroused, but professionals don’t do anything in front of the camera! They’re at work. I can’t emphasize that enough: They’re at work. Sometimes actors, like everyone else at their jobs, become highly attracted to their co-stars. What makes it different is that, being actors, they have to unearth emotions and vulnerability for their work in a way that Joe the IT dude and Mary the AA don’t have to, so things are exacerbated AND accelerated on a movie set or in theater. There’s a lot of on-set hoo-ha for a reason. But it’s not onscreen!