As a storyteller, I quickly discovered that happy endings are entirely the result of where you end the story. End the story right after the couple fall in love and solve the problem of integrating themselves with their mutual circumstance, and it's a happy ending. End the story ten years later, and one of them may have died of cancer, or their marital bliss had in the interim turned from blessing to curse. This is the way of time: given enough time, everything changes.
Our frame of reference being what it is, small changes may seem large -- especially in youth. It's no surprise to most of us that, subjectively, a year's time is quite different when you are eight to when you are thirty. The years flow more swiftly as we age. There are many ways of explaining this, I always liked the idea that relatively speaking each successive year is a lower percentage of one's entire life story. But whatever the reason, this is another factor to consider in our Happy Ending Bias.
There's also the question of carts and horses. (Or chickens and eggs, if you prefer.) Was it that we were fed the narrative of the happy ending in countless Disney and Hollywood productions that we have come to expect it in life? Though it's not particularly easy to conduct scientific research with a matter such as this, it seems more likely that Disney, Hollywood, et al are capitalizing on the expectations and hopes that rise in contrast to our certain knowledge of true Ends: Death.
Indeed, despite all the uncertainty that can arise around a mythological need such as this one, the single certainty we can count on is the inevitability of our own death. It is to try to assuage this anxiety that all of our end-narratives arise.
(It should be noted that George RR Martin's Game of Thrones, and the writers for HBO's adaptation, have not bought into the "happily ever" myth. And some of the disbelief and shock that people have recently experienced in watching that show -- especially with the "Red Wedding" episode -- is the result of that expectation being turned on its head.)