In an ordinary dream, thoughts just occur, and there is no control or choice involved. If one of these ordinary dreams includes sexual scenarios, it is still not a sin, because the dreamer had no more choice in dreaming about sex than if he were to have been dreaming about being late for work or having forgotten to put his pants on before going on stage to give a speech.
With nocturnal emissions, again, there is no choice involved – it is a spontaneous event.
Lucid dreaming is specific type of dream in which the dreamer is aware of being in a dream state and is able to control the narrative to some extent. Often, people enter this state without trying – they just happen to be in the middle of a dream during normal sleep and suddenly find themselves aware at some level that they are dreaming. Then, sometimes, they are able to manipulate the situation to their liking, even making the people around them respond the way they want. I have these kinds of dreams sometimes, and while I do have some ability to impact the direction of the dream, I am not able to make clear moral decisions about what goes on in the dream. Usually, I am already imagining a particular scenario within a dream when the dream becomes lucid, and at that point I can kind of mentally nudge things in a certain direction. Sometimes I can “undo” bad things within the dream and make them come out better. But there is no real moral decision making involved, even if the situation I find myself in happens to involve sinful behavior. Therefore, I agree with Jimmy Akin (linked above) that this kind of dream is not really a sin.
There is yet another kind of lucid dreaming, however, that some people can enter deliberately. It is essentially self-hypnosis – one gradually puts oneself into a dreamlike state, meanwhile envisioning certain scenarios that one wishes to dream about. I think it is fine if one is just going to imagine flying around, or exploring magical caves, or whatever. Where it becomes a problem is if one deliberately enters this state intending to dream about – and experience pleasure in – engaging in immoral behavior. Also, if one has a tendency to enter this process intending to engage in benign fantasy but end up fantasizing about the immoral, I would describe that as a near occasion of sin. For me, I can enter this state if I try, but I find it better if I don’t.