Jesus said that if a man looks on a woman with lust, in his heart he has already sinned with her. Also if if you hate your brother it is as if you have murder in your heart. If anger is as bad as murder and lust as bad as adultery, does this apply to dreams? If you sin in your dreams does it count as sin, since it may reflect the motive of your heart?
Remember that the Lord opened that section of His sermon by telling the people that to see the Kingdom, their righteousness had to exceed that of the Pharisees. (Matt. 5:20) I’ll guarantee you that the Pharisees weren’t going around killing people or having illicit sex.
His point was not to tell us that our lusting or anger will condemn us, but to show the Jews, and especially the Pharisees, that keeping the law in their behavior was insufficient to achieve righteousness, because God judges us on the intents of our hearts. They thought that if they controlled their behavior well enough they could become righteous. He said that if you even think about sinning it’s as bad as if you actually sinned.
No one can prevent themselves from thinking about sinning, especially if they’re asleep at the time, so no one can save him or her self. When Jesus went to the cross He took both the sins of behavior and the sins of intent with Him and paid for everything. Once we accept His death as payment for our sins, we don’t have to worry about that anymore.