I often notice these demented moments before I fall asleep. Completely nonsensical thoughts like the argument from bear bicyclist study when you need to turnkey.
Salvador Dali would hold an object like a spoon in his hand while sitting in front of his canvas and fall asleep. This would cause him to drop the spoon waking him back up and then he would draw what he saw.
In my youth I'd keep friends on the phone entirely too long, and sometimes fall asleep while talking. (How my friends tolerated me I'll never know...)
Occasionally I'd realize I was saying something ridiculous and catch myself. Most times, though, they'd ask me for clarification about whatever crazy-sounding thing I said and I'd snap back to wakefulness (briefly). I wish I had recordings of some of those things I said. They left my mind almost immediately (to the point that I couldn't respond to questions asked directly after whatever I'd said). It would be entertaining to know what I was saying. (I didn't ask friends at the time and, at >30 years ago, I doubt any of them remember.)
I read to my daughter before bed. She drifts off sometimes when I'm reading "boring" stuff (at her request) and says fun things. I keep notes and ask her about it later. I enjoy the window into her mind.
at the beginning of the night i regularly have this strain of thought: "oh shit i'm still not sleeping? but i was just planning a vacation on the moon, i must be sleeping"
I think these thoughts are happening all the time we just don't normally notice them. During the transition to sleep, some parts of our thinking mind start shutting off and the filter cracks and that's what we notice sometimes, if we remember.
I've always had difficulty falling asleep and I often notice when I enter this state and I get excited because it means I'm about to fall asleep. I'm excited because the frustration of still being awake is over.
Also, sometimes when I wake up I have a few minutes where nonsense ideas seem perfectly reasonable. Or it will feel like a complete loss of inhabitation.