where the last equality holds because $P(x, \cos x) = 0$ for every $x$. But then $P(x, 0)$ has zeroes at $x = \frac{\pi}{2}+k\pi$ for every $k \in \mathbb{Z}$. As $P(x, 0)$ is a polynomial, we must have $P(x, 0) = 0$ for all $x$, so $P(x, y) = yQ(x, y)$ for some real polynomial $Q$.

Note that $P(x, \cos x) = (\cos x)Q(x, \cos x) = 0$. For any $x \neq \frac{\pi}{2}+k\pi$, $\cos x \neq 0$ so for any such $x$, $Q(x, \cos x) = 0$. As $Q(x, \cos x)$ is continuous, we must have $Q(x, \cos x) = 0$ for all $x$. But $Q$ has strictly smaller degree than $P$ which is a contradiction.

You can write $P(u,v)=\sum_{k=0}^n q_k(v)u^k$ where the $q_k$ are real polynomials in one variable. We are given that, for any $a\in[-1,1]$, the polynomial in $u$ given by $P(u,a)$ has infinitely many zeros, because the equation $\cos u=a$ has infinitely many solutions. This means that $q_k(a)=0$ for all $k$. Since $a\in[-1,1]$ is arbitrary, this means that each $q_k$ is identically zero.