Applying the Quadratic Reciprocity law in your example we know that for $5$ to be a quadratic residue $\mod p$ and $p\
e 5$ the following conditions must satisfy:
The legendre symbol $(\frac{p}{5})$ and $(\frac{5}{p})$ are both equal, which means that 5 is a quadratic residue modulo every odd prime which is a residue modulo 5.
Example, let $p=31$ and $q=5$
$(\frac{p}{q}) = p^{\frac{q-1}{2}} \pmod q$ then $1\equiv 31^{2} \pmod 5$
$(\frac{q}{p}) = q^{\frac{p-1}{2}} \pmod p$ then $1\equiv 5^{15} \pmod{31}$
Also notice that $(\frac{p}{q})$ and $(\frac{r}{q})$ will be equal with $r$ being $p = kq+r$ such that $r= 0 \leq r < p$