There are, of course, plays without music. Even in these plays, however, there is sound, primarily the sound of the words. Where music is present, it is important for much the same reasons as the words are important.
In the first place, it may convey meaning. Music cannot convey thoughts as clearly as words can, but it may convey shades of emotion with much greater subtlety. Related to this is the creation of atmosphere, which may contradict the words and alert the audience to some incongruity (for instance, if a character is making a comforting speech, while the music conveys a sinister feeling of unease). Music can also link different scenes or sections of a play which contain similar themes and ideas by repeating the same musical pattern, like the leitmotifs in Wagner's music dramas.
Music, like language, also has an aesthetic purpose. The music may add beauty, grandeur, and pathos to a scene. It may also complement and heighten the effect of the words.