More generally, write down ideas when they happen. An idea may be crap or brilliance, but it's worth nothing for sure if you don't remember it in the first place.
Both falling asleep and using the bathroom are similarly unusual because they don't really involve anything except staying still. So I'm not surprised that you think well in the bathroom.