tl;dr: why is raising by $(p-1)/2$ not always equal to $1$ in $\mathbb{Z}^*_p$?
I was studying the proof of why generators do not have quadratic residues and I stumbled in one step on the proof that I thought might be a good question that might help other people in the future when raising powers modulo $p$.
Let $p$ be prime and as usual, $\mathbb{Z}^*_p$ be the integers mod $p$ with inverses.
Consider raising the generator $g$ to the power of $(p-1)/2$:
$$g^{(p-1)/2}$$
then, I was looking for a somewhat rigorous argument (or very good intuition) on why that was not always equal to $1$ by fermat's little theorem (when I say always, I mean, even when you do NOT assume the generator has a quadratic residue).
i.e. why is this logic flawed:
$$ g^{(p-1)/2} = (g^{(p-1)})^{\frac{1}{2}} = (1)^{\frac{1}{2}} \ (mod \ p)$$
to solve the last step find an x such that $1 = x \ (mod \ p)$. $x$ is obviously $1$, which completes the wrong proof that raising anything to $(p-1)/2$ is always equal to $1$. This obviously should not be the case, specially for a generator since the only power that should yield $1$ for a generator is $p-1$, otherwise, it can't generate one of the elements in the cyclic set.
The reason that I thought that this was illegal was because you can only raise to powers of integers mod $p$ and $1/2$ is obviously not valid (since its not an integer). Also, if I recall correctly, not every number in a set has a k-th root, right? And $1/2$ actually just means square rooting...right? Also, maybe it was a notational confusion where to the power of $1/2$ actually just means a function/algorithm that "finds" the inverse such that $z = x^2 \ (mod \ p)$. So is the illegal step claiming that you can separate the powers because at that step, you would be raising to the power of an element not allowed in the set?
Note that $1$ has two square roots modulo $p$ if $p\gt 2$.
So from $g^{p-1}\equiv 1\pmod{p}$, we conclude that $$\left(g^{(p-1)/2}\right)^2\equiv 1\pmod{p},$$ and therefore $$g^{(p-1)/2}\equiv \pm 1\pmod{p}.$$
If $g$ is a primitive root of $p$, and $p\gt 2$, then $g^{(p-1)/2}\equiv 1\pmod{p}$ is not possible, so $g^{(p-1)/2}\equiv -1\pmod{p}$.