Example 9 (2002 Australian National Mathematics Competition) 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.
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)$,
either $n+2= \pm 1, 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$.
Since 4 is not a prime number, there are 5 values of $n$, which are $-3,-1,0,1,3$.