From Deus Ex Machina, A Penis Ex Machina is when a sex scene is unnecessarily dropped into the plot of an otherwise decent film or story in order to boost the ratings.
Some sex scenes are vital to plot, but this describes only when they blatantly serve no relevant purpose to the story-telling.
Alternatively, it can be used to describe a twist in the plot of a pornographic film in order to bring about the vital sex scene. When a girl in the plot is constantly refusing sex, and then something triggers her suddenly to lust after the male protagonist, this is a Penis Ex Machina.
Person 1: "I heard the movie we're going to has a spicy sex scene!"
Person 2: "Is it part of the plot, or does it come about through Penis Ex Machina?"