This is just my opinion, so take it as you will.
I think part of that comes from the fact that when we are truly happy and in a good place, we naturally don't think to question or explore ourselves to understand why. We just accept that things are going good and ride the wave. When things get rough, when we are in pain, whether emotional, physical, or psychological, we begin to question why so that we might try to escape the pain. This internal analysis helps us get in touch with that fickle muse within us all.
I know that some of my best quality writing has come during difficult times in my life when I was battling depression, or horrible insomnia, or emotional devastation from a disastrous ending to a relationship. Those times of pain and difficulty made it easier to access those feeling and thought patterns, allowing my work to reflect those emotions in my characters. A good example is a short work I did years ago. The first section was written as I was just coming out of a long stretch of insomnia and had just broken up with a girl. I came back later and wrote another chunk after I had leveled out, then stuck it in a cabinet and forgot about it. When I came across it much later on I realized how much I liked the first bit and abhorred the second.
I think the process works for everyone a little differently, but as many have observed, some of the greatest artists (no matter their field or subject of art) where the most troubled people in life. Van Gogh, Robin Williams, Freddy Mercury: all drew on the pain of their personal lives to deliver momentous and lasting art to the world.
I'm not saying creation is pain, but many find their stride in their darkest moments.