In May 1995, I was asked to write a ten-minute piece for the American Composers Orchestra. Fortunately I was able to get to work right away, since for some time I'd been thinking of ideas for an orchestra piece. On the other hand, without an idea, composing is more or less impossible.
People can get ideas from all over the place.
Beethoven used to get his during long walks in the forest, sketchbook in hand. Sometimes he would let an idea sit for months, or even years, before it emerged as a piece of music. All of us have probably had the experience of walking and suddenly stopping because we've been struck by a thought. That thought can be an inner voice, figuring out how to solve a knotty personal problem, or it can be a more abstract idea, such as an image or a sound. Most people, I imagine, can hear music in their heads at least part of the time, and occasionally it's music that has never been heard before.