Creativity as a whole is a hard thing to concretely study. However, a slightly easier question than "where does creativity come from?" is "how do epiphanies work?" Those sudden flashes of new ideas happen when your brain connects up associations that don't normally go together, like bacon and popcorn.
The process starts when your more rational, top-down conscious thinking system struggles with a question it can't seem to solve. With possibilities exhausted, you start to lose focus, and as a result, your attention shifts. At this point, your executive control system bows out and the problem gets dumped into the more reflexive, impulsive, emotional brain.
Your brain is designed in such a way that when you stop actively working the problem, your unconscious systems help out by taking over, continuing the associative matching exercise. It's like an architect who, out of ideas, kicks a problem down to the site foreman, saying, "See what your guys can do with this."
However, with the unconscious areas of your brain heading up the search, there is no longer any direction or intervention from the executive control center of your prefrontal cortex. This also means working without the benefit of the attention network (singular focus) or working memory (recent information).
This might sound like it would hamper the whole enterprise, but without the scrutiny and self-criticism of top-down control, the bottom-up process is allowed to operate unimpeded. Associations connect less powerfully and more randomly. That may seem like a negative, but the wider you cast the net, the more likely it is that a solution will surface.
The magic is in the novel recombinations that arise through loose association—the ones that would normally be suppressed by your prefrontal cortex, dismissed as arbitrary and unsystematic. In this situation, your new connections are not only free to form but free to take root. It only takes a few to get that novel guitar riff or chess move started.
While your prefrontal cortex is on hiatus, should you chance to encounter some new stimulus—like a tub of water you displace by plopping into it—you, like Archimedes, can spot new associations bubbling up unexpectedly.
I'm talking about that "Eureka!" moment when neural circuits suddenly connect and, seemingly out of nowhere, you are struck with a new insight. If you're Archimedes, you discover a new principle, a central tenant of physics. Eventually, you get a law named after you. Much later, when the twentieth century rolls out, "Eureka" proves to be a marketable name for an upright vacuum cleaner.
Not bad for a slow day at the bath-house.