Like any other scene, a sex scene needs to have purpose - and that purpose should more than just to titillate the reader. The main character might discover something about themselves or another person. There might be an emotional change within characters such as liking turning to love, love turning to indifference, indifference turning to hatred or hatred turning to lust. Characters reach out emotionally and physically, and perhaps their needs are met and perhaps they aren't, but the story will move on because of the emotional change.
Sex scenes are useful as story turning points - as Isabel says to herself in Adultery for Beginners, she would never be Neil's faithful wife again. She can't go back, so the story has to go forwards. Becca, in Another Woman's Husband, has been dreaming about sex with Paul, but finds the reality inconclusive and unsatisfactory and as a result begins to move away from him emotionally.
Scenes have many purposes: to convey information, to develop character, to add humour, to move the story on etc. Sex scenes should have just as many purposes as any other scene, because that's the only reason for writing them. Sex may be going on in a scene, but the mechanics aren't the reason readers are reading. They're finding out what happens next in the story. If nothing is happening, if nothing is changing, if all that is going on is mechanics, then you need to add some purposes. And if you can't think of any, then don't write the scene.