While I prefer happy endings in general, I enjoy a good unhappy ending every once in a while because they make the happy endings all the more satisfying. If everything was predetermined to be a happy ending the predictability of it all would dampen the suspense when our heroes are in danger. There has to be consequences sometimes in order for the threat of those consequences to have any meaning or implied danger.
Some films would just be fairly conventional with a happy ending, or at least an ending where the villain doesn't win or accomplish his goals. Imagine
Seven or
The Usual Suspects or
Arlington Road without their downbeat endings? They'd hardly be memorable. The endings made those films. Which is not to say throwing in a bad guy wins bummer ending always works. Lots of films tried to copy the formula and failed miserably. But in the hands of the right writers and directors it can turn the pedestrian into the remarkable.
For example, I think War of the Worlds (2005) would have been a better movie with a bittersweet ending in which the character played by Tom Cruise had turned up at his in-laws' place to break the news that he had managed to save his daughter but the son had died.
Oh, and just to toss another Cruise scifi film into the bonfire of unhappy endings, everything that happens after Chief Anderton is lowered into the prison chamber and the white light flashes in
Minority Report is just him dreaming while he's in an induced coma in the prison for the rest of his life. Lamar (Max von Sydow) successfully frames Anderton and gets away with the murder of Agatha's mother, PreCrime continues to put away innocents and is expanded across the whole country, and the PreCogs remain enslaved and abused.
The key is the line from the prison caretaker:
"They say you have visions. That your life flashes before your eyes. That all your dreams come true."
Anderton's visions after the white light were of catching the man responsible for framing him and murdering Agatha's mother, freeing the PreCogs from enslavement and closing PreCrime, and reconciling with his wife and having another child. All his dreams came true.