Yea, i do understand, it happen at times,a friend of mine was feeling embarrassed even to confess to a priest .but the priest gave a wonderful advice ,he said if it happens in your sub-conscious mind, while we are asleep,its not a sin,since we are not conscious,if we are conscious then it’s a sin ( to sin we are to be conscious) .and if we are semi-conscious, but not full consent to sin, you can make your own judgement on this, pray and take the decision with a good conscience.asking Jesus to forgive you trusting his mercy, we can receive Holy Communion,but if you feel you sinned while sub-conscious mind or remember it, then don’t receive Holy communion,so our conscience won’t prick us or hurt or have a guilty feeling.Therefore if you keep thinking lustful thoughts before sleeping more or less you’ll end up in wet dreams,lust is one of the 7 most deadly sins.
Try to say the Rosary or read a passage of the Bible ,or just call on the Name of Jesus and Mary,with Faith and Trust,and ask them to take care of you, during the nights to keep holy you thought or precious Blood of Jesus purify my thought,word and actions .also ask the intercession of your guardian angle and patron saints to pray for you,and do confess them!,God Bless ,Hope it helps
There is a verse in the bible which mentions it
Jude 1:8 Yet in the same way these dreamers also defile the flesh, reject authority, and slander the glorious ones.
1 Corinthians 11:27 Whoever, therefore, eats the bread or drinks the cup of the Lord in an unworthy manner will be answerable for the body and blood of the Lord. 28 Examine yourselves, and only then eat of the bread and drink of the cup. 29 For all who eat and drink[h] without discerning the body, eat and drink judgment against themselves. 30 For this reason many of you are weak and ill, and some have died.
Psalms 119:9-11 9 How can young people keep their way pure? By guarding it according to your word.10 With my whole heart I seek you;do not let me stray from your commandments.11 I treasure your word in my heart,so that I may not sin against you.