5. Given $f(x)=x^{2}+p x+q, p^{2}+1 \leqslant 4 q+$ $2 p$ holds. Let the set of real solutions to the equation $f(x)=x$ be $P$, and the set of real solutions to the equation $f(f(x))=x$ be $Q$. Then ( ).
(A) $P=Q$
(B) $P \subset Q$
(C) $Q \subset P$
(D) $P \not \subset Q, Q \not \subset P$
5.A.

When $p=1, q=0$, $f(x)=x^{2}+x$.
Obviously, we can get option (A). Here, we also provide a theoretical basis.
From the given, we have $(p-1)^{2}-4 q \leqslant 0$, thus,
$$
f(x)-x=x^{2}+(p-1) x+q \geqslant 0
$$

holds for any $x$. For any $x_{0} \in P, f\left(x_{0}\right)=x_{0}$.
Therefore, $f\left(f\left(x_{0}\right)\right)=f\left(x_{0}\right)=x_{0}$.
Hence, $x_{0} \in Q$. So, $P \subseteq Q$.
On the other hand, for any $x_{1} \in Q$, then
$$
x_{1}=f\left(f\left(x_{1}\right)\right) \geqslant f\left(x_{1}\right) \geqslant x_{1} \text {. }
$$

Therefore, $f\left(x_{1}\right)=x_{1}$, i.e., $x_{1} \in P$. So, $Q \subseteq P$.
In summary, $P=Q$.