Jeanette Winterson once wrote what was to her the main difference between writing for children and for adults: "Writing a kids' book was no easier than adult fiction, or less demanding, or simpler to invent. The only difference I could find was that there has to be an inherent optimism - which is not the same thing as a happy ending. Sadness, difficulty, fear, danger, loneliness, sacrifice, none of these are impossible for kids to cope with, but bleak hopelessness, and the cynicism that comes with believing that nothing can be done, are not the stuff that kids are made of - we do that to them later on."
This " inherent optimism" that Winterson mentions is what Bruno Bettelheim described in his book The Uses of Enchantment as a way of making children want to face life events at all. As if you wouldn't want to try something at all if you didn't think you could succeed. That's why a "happily ever after" was considered to him a teaser, to stimulate one's will. And that "later on" is the maturity of adulthood. As Bettelheim says, "only in adulthood can any intelligent understanding of the meaning of one's existence in this world be gained from one's experiences in it", and that's why it is later on.
And now matching both author's visions, I quote Winterson again:
"You play. You win. You play. You lose. You play."
Which means that there are wins and losses in live and that is living itself.
A happy ending in a children's book is simply a defiance of trying.