To get the codimension, if the curve corresponding to $x = (x_i \in H^0 (\Sigma, \Omega_\Sigma^i))_{i=1}^n$ fails to be integral, then the equation $T^n - x_1 T^{n-1} + x_2 T^{n-2} + \dots $ defining the curve splits as a product of two such equations, say $T^k - y_1 T^{k-1} + \dots + (-1)^k y_k $ and $T^{n-k} - z_1 T^{n-k-1} + \dots + (-1)^{n-k} z_{n-k}$. We have $y_i, z_i \in H^0 ( \Sigma, \Omega_{\Sigma}^i))$ so the dimension of the locus where this occurs is

$$ \sum_{i=1}^k \dim H^0 ( \Sigma, \Omega_{\Sigma}^i) + \sum_{i=1}^{n-k} \dim H^0 ( \Sigma, \Omega_{\Sigma}^i) = k^2 (g-1) +1 + (n-k)^2 (g-1) + 1$$ and since the total dimension of the Hitchin base is $n^2 (g-1) +1$, the codimension is $$ (n^2 - k^2 - (n-k)^2)(g-1) -1 = 2 k (n-k) (g-1) -1$$ which is minimized with $k=1$ or $k=n-1$, giving a total codimension of $2 (n-1) (g-1)-1$.

We can also use this factorization to check that the non-integral locus is closed. It is the union over $k$ of the image of the map from $\prod_{i=1}^k H^0 ( \Sigma, \Omega_{\Sigma}^i)) \times \prod_{i=1}^{n-k} H^0 ( \Sigma, \Omega_{\Sigma}^i))$ that sends $y_1,\dots, y_k, z_1,\dots, z_{n-k}$ to $$(T^k - y_1 T^{k-1} + \dots + (-1)^k y_k ) (T^{n-k} - z_1 T^{n-k-1} + \dots + (-1)^{n-k} z_{n-k}).$$ It suffices to check that this map is proper, from which it follows that the image is closed.

In fact, it is finite, because the $y_1,\dots, y_k, z_1,\dots, z_{n-k} $ all satisfy monic polynomial equations with coefficients polynomials in $x_1,\dots, x_n$. Indeed, we can express the $y_1, \dots , y_k$ formally as polynomials in the roots of $T^n - x_1 T^{n-1} + x_2 T^{n-2} + \dots $, and the roots certainly satisfy a monic equation, so any polynomial in the roots does as well.