Here is a little more information on how the music became connected to Ibsen's play:
"The Peer Gynt Suite was first composed by famed Norwegian composer Edvard Grieg (1843-1907) in the year 1876. All eight songs are an effort to put a musical interpretation to Henrik Ibsen's play by the same name, which was written about a decade earlier in 1867. The play is approximately 5 Acts (dependent on which version you follow) and spans from Norway to Morocco to Egypt before returning home. The play has surprisingly few principal characters, but of course all action follows the tragic (and possibly delusional) Peer Gynt in his travels and deeds. Supporting roles are filled by his mother Aase, a plain girl Solveig who is his faithful love, a young bride Ingrid, The Troll King, and finally the play's "judge" of humanity, the Button Molder. The play is quite entertaining, with several ending altering plot twists."
Many plays have music associated with them. Sometimes previously existing musical pieces are re-used, but in many cases, new works are written to accompany theatrical productions, just as musical sound tracks are used with movies today.
Edvard Grieg was a composer, and was hired to write the music to accompany Peer Gynt. (Ibsen asked him to write it.)
Ibsen commissioned Grieg to write the incidental music to Peer Gynt. There are over 40 scene changes in the play, and so music was used to fill the gaps between scenes. It also helps in the characterisation and conveys the mood of the scene more profoundly than words. The two orchestral suites were compiled by Grieg some years after the first productions. Another reason why Ibsen might have wanted to include music is that his audiences would have been mainly used to vaudeville and comic opera and would have found it too heavy-going to sit through five acts of solid verse.