Observation of Emergent $\mathbb{Z}_2$ Gauge Invariance in a Superconducting Circuit