structure in modular arithmetic
If you know the Fermat's little theorem, that is, $g^{n-1} = 1 \mod n$, then you can understand what you found. 

The point is that 

$$b^2 = g^{2k + n-1} = g^{2k}g^{n-1} = g^{2k} = a^2 \mod n$$

Therefore, $b = a$ or $b = -a$ in $\mathbb{Z}_n$. But $b = -a$ means that $b = n-a$, since $n = 0$ modulo $n$.