c.1500, from Middle French galerie "a long portico" (14c.), from Medieval Latin galeria, of uncertain origin, perhaps an alteration of galilea "church porch," which is probably from Latin Galilaea "Galilee," the northernmost region of Palestine (see Galilee); church porches sometimes were so called from being at the far end of the church.
Super altare Beatæ Mariæ in occidentali porte ejusdem ecclesiæ quæ Galilæ a vocatur. [c.1186 charter in "Durham Cathedral"]Sense of "building to house art" first recorded 1590s; that of "people who occupy a (theater) gallery" (contrasted with "gentlemen of the pit") first by Lovelace, 1640s, hence to play to the gallery (1867).
To direct a performance toward less sophisticated tastes; by extension, to attempt to gain approval by crude or obvious means: “The cast of the play was a decidedly mixed bag of youthful method actors and old hams who played to the gallery.”