<
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).
see play to the gallery; rogues’ gallery.