Why is raising by $(p-1)/2$ not always equal to $1$ in $\mathbb{Z}^*_p$? (Manipulating powers modulo p) 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?

Taking roots in modular arithmetics doesn't work.
For example check this:
$9 \equiv 4 \pmod 5$, but $2 \equiv 3 \pmod 5$, doesn't hold.
Now to the problem. If $(g,p) = 1$, then 
$$g^{\frac{p-1}{2}} \equiv 1 \pmod p \text {    or    } g^{\frac{p-1}{2}} \equiv -1 \pmod p$$
This is because:
$$g^{p-1} \equiv 1 \pmod p$$
$$g^{p-1} - 1\equiv 0 \pmod p$$
$$(g^{\frac{p-1}{2}} - 1)(g^{\frac{p-1}{2}} + 1) \equiv 0 \pmod p$$
Obviously only one of the factors can be 0 modulo $p$.
