Thoughts when you aren’t awake or conscious of it

I get that when I am awake I can consciously choose what I think to control my feelings. However, what about thoughts that wake you up in the middle of the night? Or yesterday, I was walking with a friend and I was not consciously thinking about this comment he had made 15 minutes earlier. I was trying to think about the thing I was talking about. The comment he made kept intruding in my thoughts and distracting me from thinking about the thing I was talking about (which was positive). I didn’t have time to stop and do the model while we were walking (that seems weird). This same thought hit me as soon as I woke up this morning, it actually woke me up.

How do I release these unconscious thoughts, both in the moment and when I’m sleeping?