mid-15c., "covered walk or passageway, narrow and partly open passageway along a wall," from Old French galerie "a long portico" (14c.), from Medieval Latin galeria, of unknown 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, perhaps 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. In reference to theaters, of the section with the highest, cheapest seats; hence "people who occupy a (theater) gallery" (contrasted with "gentlemen of the pit") first by Lovelace, 1640s, hence to play to the gallery (1867).