Film music is a voice of cinema. Usually, that voice will say something new with every movie. But there is a number of occasions where film music will incorporate references to existing pieces of music for different reasons and purposes.
1) The Sequel : Easily understandable, music of a film in an established franchise is likely to draw on the same musical canvas as the previous film or films. That is expected, demanded and usually appreciated. But there are exceptions: a composer can draw too much from the earlier film (like The Ring or Rush Hour sequels), leaving too little room for originality. Or, on the flipside, a change of composer in the franchise can leave the sequel completely devoid of references to the original material (such as, famously, the X-Men or Alien series)
2) The Hidden Reference: A composer may decide to hide a reference to a piece of classical or folk music or an ancient song knowing full well that no one but the most erudite will detect it. Why does he do it? Sometimes the emotional contents of that melody does its job even if the listener fails to recognize it. Such it is with the most famously-quoted piece of medieval music: the Dies Irea. Countless film scores have used its macabre tones to great effect (Escalation, Demolition Man) even if the average audience couldn’t be expected to pick up on it. Sometimes, the piece is well known (like Beethoven's “Ode to Joy” in Die Hard) but its use is so subtle that none but the most attentive are meant to spot it.
3) The Obvious Reference: This existing piece of music that is fully expected to be recognized. It is meant to create a little wink to the audience, usually for comedic purposes. Such is the case whenever a national anthem is referenced (like in We’re Back – A Dinosaur’s Story), or something of great cultural relevance like the wedding march.
4) The Controversial Reference: This category has a name. And that name is James Horner. This occurs whenever a composer makes a reference to another piece (whether classical or more film music) for no other purpose than the music itself. Sometimes we also find that those are self-references. Of course the line is very thin between an “homage” and a “rip-off”, hence the controversial nature of these references. Some love them, others loathe them. The whole topic would require an article onto itself.
One thing is for sure, detecting these four kinds of references is one of the film music fan’s biggest pleasures.