Consider the polynomial $$f(x)=x^2 - 6 x + 5$$
The constant term here is $5$, which is prime.
However, \begin{align}f(5)&=5^2-6\times 5+5\\
&=25-30+5\\
&=0\end{align}
And thus $5$ is a root of the equation.
Therefore, I have disproved your hypothesis through contradiction
For higher degree polynomials, anything of the form $$f(x)=(x\pm p)(x+1)^a(x-1)^b$$ for $p$ prime, and $a,b$ integers will form a contradiction.
Examples include $$x^4 + 8 x^3 + 6 x^2 - 8 x - 7 = (x+7)(x+1)^2(x-1)$$ which has $p=-7$, $a=2$, $b=1$
and $$x^6 - 14 x^5 + 11 x^4 + 28 x^3 - 25 x^2 - 14 x + 13 = (x-13)(x+1)^2(x-1)^3$$ which has $p=13$, $a=2$, $b=3$
To add the constraint that $f(1)\neq f(-1)\neq 0$, then we can choose $$x^3 - 11 x^2 + x - 11=(x-11)(x^2+1)$$
Here we have $f(1)=-20$, $f(-1)=-24$ but $f(11)=0$
As long as the second polynomial is an irreducible one, with a constant of $1$, then this will form a contradiction
The key point here is that $a-b|P(a)-P(b)$ (if you haven’t seen this already you should try proving it, it’s a nice exercise).
From here, if $P(n) = p$, then $p$ divides $P(n+kp)$ for all positive $k$. But since all of these are prime, we get that $P(n+kp)=p$, and so $P$ takes the same value infinitely many times, and hence is constant, contradicting the degree condition.
Best Answer
This is from IMO Shortlist 2009.
Hint 1: For any function $T: \mathbb{Z} \rightarrow \mathbb{Z}$, let $S_T(n) $ be the number of solutions to $T^n(y) = y$.
Break up the image of $T$ into various cycles. Suppose that there are $C_T(n)$ (non-negative integer) cycles of length $n$.
Show that $S_T(n) = \sum_{k\mid n} kC_T(n)$.
There is at least one solution where this is the only fact about $T$ that we need.
Hint 2: For poylnomials with integer coefficients, $a-b \mid P(a) - P(b)$.
There is at least one solution where this is the only fact about integer-coefficient polynomials that we need.
Hint 3: A polynomial is non-constant iff $P(x) = k$ has finitely many solutions for any $k$.
There is at least one solution where this is the only fact about non-constant polynomials that we need.
Corollary: Show that if $P(n)= S_T(n)$, then it is a constant.
(This requires some work.) There are several ways to do this.
Without giving too much away, you don't have much options other than looking at terms like $P(0), P(1), P(p), P(pq), P(p^2), P(p^2q), P(p^k) \ldots$ for distinct primes $p, q$.
For example, (I don't think these statements are that helpful in the proof, but it gives you an idea of how they can be used.)
This is how I did it (which I think is distinct from their solutions.)