Theme music is, essentially, a form of music that is associated in the mind of the listener with characters or events in the work it accompanies.
Theme music has its origins in theater and opera. Traditionally, characters and moods in these works would be accompanied by musical motifs that would oftimes have a narrative aspect to them also. The hero's entrance music might vary from triumphant to heartrendingly dismal, depending on the context. Opera in particular is strongly themed: although a morality play might have recurring musical phrases that consistently accompany events, it is almost expected that the entrances and actions of characters in an opera could be recognized by an audience member with closed eyes.
Oni no Ng reminds me that Wagner with his Ring Cycle invented the idea of leitmotif, which is the association of musical themes with characters, with events, with places, and just about anything else that could be themed.
With the rise of film and television, these notions of themed music returned. Epic movies from film's earlier days sometimes heavily resembled theater (a strong example being Gone with the Wind), and, in order to draw in many viewers, filmmakers explored as many different sensory stimuli as they could (see Smellovision), and in many cases, decided that having musical motifs attending characters would help audience members identify with characters, and in turn develop a stronger appreciation for the movie.
With the introduction of advertisements to television, the desire to stimulate brand recognition became severe. An era of brightly colored bottles, catchy slogans, and infuriatingly memorable jingles dawned. Tension, apprehension, and dissension had begun. Many millions of regular television viewers are easily able to recall the music for a number of products, even (in some cases) decades after the product in question had disappeared from the market and its parent company had folded up.
George Lucas, in making Star Wars, decided that what he wanted to make was a "space opera" — characters (and in some cases, groups of characters) are identified with themes. Just about every adult American (and many younger ones) can recognize the Imperial March (Darth Vader's theme), the Star Wars main theme, and in some cases, a whole smattering of other themes from the film. Many later movies used the model that John Williams (the composer for Star Wars, then a rising star, now one of the most prominent composers in the world) had founded to create their music.
Television music also was strongly themed at this point (and has continued to be). Many, many people can sing the theme songs from such shows as Gilligan's Island, The Flintstones, Bonanza, and dozens of others. These shows are, in some cases still persistent simply because of the catchiness of their theme music.
As video games have risen, and the technology accompanying them has developed, they have also incorporated theme music into their oeuvre. Nintendo's games in particular, with their strongly character-based series, have recognizable theme music, to the point where there is a Japanese concert series (the Orchestral Game Concerts) which plays these themes to sold-out crowds.
Theme music is an important part of the multisensory enjoyment of media, and will most likely continue to develop and aid future works.