There isn't a straight forward response to this, but many factors are involved.
Relating to music theory - the key, chord progression, voicing can have a huge impact on the emotion of a piece of music. For example, minor keys are generally perceived as "sad" and major key, happy. In most pop songs, you will find a similar progression of major keys in uplifting tracks - think Bruno Mars, Pharel Williams, etc. where as slower piano ballads - think Adele, Lana Del Rey, tend to follow a minor key progression. Things like tempo, key signature, time signature will also play a huge roll.
Instrumentation and articulation - the type of instrument it uses also reflects on that. Instruments like the french horn in movies are particular "heroic", while things like a violin playing quick notes can be perceived as a "racing" feeling. Articulation refers to how a note is to be played on an instrument. An easy example would be vibrato - when the note is alternative between two pitch creating a "wavey" effect.
Type of sounds - this is huge in our current musical world. In the example of Dark Knight, there are many electronic elements that make it especially dark and heroic. Generally, lower notes create drama, and higher notes create tension.
Musical phrasing and emotion: This may be the most important thing, how each musician plays will give much of its characteristics. Imagine if all the notes were played in the same dynamic range, not giving any live or emotion to a piece of music.
As mentioned, there are cookie cutter equation on determine why a song gives a certain emotion. This all depends on everything said above.