In the context of QCD (and more generally, any quantum gauge theory in even dimensions), the $\theta$-term is $$ \frac{\theta}{8\pi^2}\langle F_A\wedge F_A\rangle = \frac{\theta}{32\pi^2}\langle F_A^{\mu\nu}, F_A^{\rho\sigma}\rangle\epsilon_{\mu\nu\rho\sigma} $$ and its integral over spacetime is not exactly gauge invariant—instead it transforms under a general gauge as $$ \int\frac{\theta}{8\pi^2}\langle F_A\wedge F_A\rangle \overset{g}{\mapsto} \int\frac{\theta}{8\pi^2}\langle F_A\wedge F_A\rangle + \theta n_g \tag{1}\label{1} $$ where $n_g \in \mathbb Z$ is the winding number of the gauge transformation $g$ (Ref. Tong’s lecture notes, §2.2). (Edit: I think I am confused—\eqref{1} may be wrong.)
(Bonus question: what does \eqref{1} look like with $\hbar$ not set to unity?)
Ultimately, physical predictions are made with the partition function or ‘quantum-mechanical amplitude’ given by the path-integral $$ \mathscr A = \int_{\partial\Omega}\! \mathcal D[\psi, A] \exp\left(\frac{i}{\hbar} \int_{\Omega}\! \mathcal L\left[\psi, \nabla_{\!A}\psi, F_A\right]\right) .$$ This is an integral over all gauge field configurations $A$. However, it appears that two physically equivalent gauge field configurations $A$ and $A^g$ separated by a ‘large’ gauge transformation $g$ would contribute differently to the partition function: $A$ contributes $\exp(\frac{i}{\hbar}\int\mathcal L)$ while $A^g$ contributes $\exp(\frac{i}{\hbar}\int\mathcal L)\exp(i\theta n_g)$, which appear to differ by a phase.
Doesn’t this make $\mathscr A$ ill-defined, unless $\theta \in 2\pi\mathbb{Z}$? How does the $\theta$ term not spoil gauge invariance in this sense?
Note: I think I might be confusing “the integral of the $\theta$-term is discrete over instanton configurations” with “the $\theta$-term is gauge invariant modulo a discrete additive factor”. Are both of these accurate?