Example 31 (2002 Australian National Mathematics Olympiad) Given the polynomial $p(n)=n^{3}-n^{2}-5 n+2$, find all integers $n$ such that $p^{2}(n)$ is the square of a prime number.
Solve: Since $p(n)=(n+2)\left(n^{2}-3 n+1\right)$. Let $p$ be a prime, then the necessary and sufficient condition for $p^{2}(n)=p^{2}$ is $p(n)= \pm p$, i.e., $(n+2)\left(n^{2}-3 n+1\right)= \pm p$.
There are only two possibilities:
(1) $n+2= \pm 1, n^{2}-3 n+1= \pm p$,
(2) $n+2= \pm p, n^{2}-3 n+1= \pm 1$.
In case (1), $n=-1$ or -3. When $n=-1$, $n^{2}-3 n+1=5$ is a prime; when $n=-3$, $n^{2}-3 n+1=19$ is a prime.

In case (2), from $n^{2}-3 n+1=1$ we get $n=0$ or $n=3$, and from $n^{2}-3 n+1=-1$ we get $n=1$ or $n=2$.

When $n=0$, $n+2$ is a prime; when $n=3$, $n+2=5$ is a prime; when $n=1$, $n+2=3$ is a prime; when $n=2$, $n+2=4$ is not a prime.
In summary, all possible values of $n$ are 5: $-1,-3,0,1,3$.