Praying is a form of meditation and helps you solve problems the same way that meditation does. Current neurological thinking is that the two halves of the brain are actually more like two brains. Your left brain is what you think of as ‘you’, and your right brain is what you think of when you consider your so-called subconscious.
Meditation, and prayer, help integrate the two halves. Prayer in particular is a form of spiritual surrender. By “letting go and letting God,” you relax your left brain’s hold on a problem space, and allow your whole mind to roam over it and come up with solutions. The sudden flashes of insight that often seem to come from God are coming from this interplay.
Meditation simply helps integrate the two halves without any problem focus. Insights flash the exact same way, just about nothing in particular.