Example 2 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. (2002 Australian National Mathematics Competition)
Analysis Notice that the right side can be factored, and using the fact that the positive divisors of a prime number are only 1 and itself.
Solution Let $p$ be a prime number. Then $p^{2}(n)=p^{2}$ holds if and only if $p(n)= \pm p$, since $p(n)=n^{3}-n^{2}-5 n$ $+2=(n+2)\left(n^{2}-3 n+1\right)$. Therefore, either $n+2= \pm 1 \cdot n^{2}-3 n+1= \pm p$.
Or $n^{2}-3 n+1= \pm 1, n+2= \pm p$.
(1) When $n+2=1$, $n^{2}-3 n+1=5$.
(2) When $n+2=-1$, $n^{2}-3 n+1=19$.
(3) When $n^{2}-3 n+1=1$, if $n=0, n+2=2$; if $n=3, n+2=5$.
(4) When $n^{2}-3 n+1=-1$, if $n=1, n+2=3$; if $n=2, n+2=4.4$ is not a prime number.
Therefore, there are 5 values of $n$, which are $-3,-1,0,1,3$.