Why am I more "musically" creative in the last 30 seconds before falling asleep?
This is quite a well documented phenomenon - stereotypically these moments of creative insight occur in the shower. A google for 'psychology aha moment' or 'neuroscience creative aha' will give you some articles, in Psychology Today for instance, talking about this.

One characterisation of thought is that links between neurons are created and by travelling down the intricate pathway, you have the thought. A lot of conscious thought is driven by "picking" the "quickest" path and travelling down that, as it is economical in terms of energy use.
One understanding of creativity is that it is combining of existing ideas in novel patterns. When you enter a more relaxed state, or even just a more distracted state such as showering or exercising, your brain is free to try novel combinations as you are not consciously driving it down specific well-worn pathways (the "easy" paths).

Mark Beeman has done research on this, which he calls it insight. For more information, see the article he co-wrote "The Aha! Moment: the Neural Basis of Solving Problems with Insight".

For another explanation, Alice Flaherty has done research linking these moments to dopamine release, which is more abundant in our brains when we relax. For more information see the publication "Frontotemporal and dopaminergic control of idea generation and creative drive".