If $-1$ is a quadratic residue modulo $p$, then we have $-1\equiv a^2\pmod p$, hence
$$
(-1)^{\frac{p-1}2}\equiv (a^2)^{\frac{p-1}2}=a^{p-1}\equiv1\pmod p
$$
Hence $p\equiv1\pmod4$ . Now if $p\equiv1\pmod4$, then
$$
-1\equiv \left((\frac{p-1}2)!\right)^2
$$
by Wilson's theorem.
If $-1$ is a quadratic residue modulo $p$, then we have $-1\equiv a^2\pmod p$, hence $$ (-1)^{\frac{p-1}2}\equiv (a^2)^{\frac{p-1}2}=a^{p-1}\equiv1\pmod p $$ Hence $p\equiv1\pmod4$ . Now if $p\equiv1\pmod4$, then $$ -1\equiv \left((\frac{p-1}2)!\right)^2 $$ by Wilson's theorem.