Fractional Vortices, $\mathbb{Z}_2$ Gauge Theory, and the Confinement-Deconfinement Transition