Isn't it odd that I Dreamed a Dream, a very sad song from "Les Misérables", is written in a major key? Isn't it a mismatch between the lyrics and the music?
Nope! It's not necessarily a mismatch. The major or minor quality of the key a song is in is only one of many, many qualities that determine its emotion. It gets to the point that a major song can be very sad, and a minor song can be very happy, depending on the context.
For concrete examples, "Last Train Home" by the Pat Metheny group (listen on Spotify) is in a major key, but it's bittersweet and if it had lyrics, it's easy to imagine that they'd be sad. In contrast, "Stray Cat Strut" by the Stray Cats (Spotify) is in a minor key, but it's a deliberately silly and fun song.
In the specific case of "I Dreamed a Dream," my interpretation is that it has shades of positive emotions (and was therefore written in a major key) because it's about how the singer remembers happy periods of her life. The reason it's such a sad song is because her life now is full of bitter pain, and she's losing hope that life will ever return to what she remembers. Writing the song in a minor key would have emphasized the pain the singer felt presently instead of the peace she wishes she could keep.
This is a trademark of Randy Newman, purposely mismatching a happy tune to sad/nasty lyrics. This isn't necessarily done with major/minor keys. For example, "In Germany before the war" has a beautiful tune and seems really sensitive, but the lyrics are about a child murderer.
Technically, matching musical content to lyrics is called 'prosody'; normally, getting prosody wrong (eg if the lyrics were 'sing high, sing low' and 'low' were sung on a higher note than 'high') makes one feel that the song wasn't written properly. But when this is done in the hands of a master....
As noted by other answers, major keys don't necessarily equate to happiness, nor minor keys to sadness, but with regard to "I dreamed a dream", consider the text.
Fantine starts singing in D major about how she used to be happy--almost reminiscing. That continues through the second verse--still in D major chord. But then something changes. There's a sudden jump to a B7 chord and when the tigers come at "night", E minor. Then another B7 but this one resolves to E major. Then A7, which would the dominant of the original D major, but as Fantine's hopes are torn "apart" that A7 resolves to D minor. Then another A7, but this time Fantine, with great effort, summons up enough energy to--with great effort--pull herself together for another verse that starts with more happy reminiscence.
The third verse briefly heads toward depressing thoughts about "when autumn came", but Fantine pulls herself together (and into the higher key of E major) where--despite the futility--she forces herself to keep alive her dream of a better life.
Unlike website coding and other technical disciplines, music is artistic and relies on the interpretation of the consumer. Asserting that a major key must be used for emoting happiness and vice versa is more than likely a bit of academia created by music scholars who may lack the complete artistic gift. The movie Amadeus brings this home. The protagonist (I've long forgotten his name), a theoretical virtuoso, spent his life in Mozart's shadow and died wishing that he had Mozart's gift. Artists play. The others teach. It follows that in the case of music, we shouldn't necessarily listen to what other mortals say unless they can honestly defend their "rules".