Any random thought can come into your head or into your dreams. You have as much control over it as you do over junk mail in your mailbox.
What you do with it is up to you. You can decide to accept it or reject it.
I love the junk mail analogy!!!! I'm going to start using that one from now on. I have struggled with intrusive thoughts off and on my entire life - at times I even became afraid of the thoughts (which makes them more prevalent). Thinking of them as junk mail - or pop up ads - is helpful, actually. Close them, or throw them away, and move on.
I've had all kinds of crazy, gross sexual dreams. I always feel really gross about it when I wake up. But they're just dreams, and don't require any more thought than that. The good thing about dreams is that they don't hang around in memory too long, usually. They fade into some nondescript vague haze within a matter of hours, usually. At least for me.