Solution by sqing-inequality-BUST and ja..
The solutions are
f(x)=x,
and, for any constant c≤0,
f(x)={x,−x,x≥c,x<c,
or
f(x)={x,−x,x>c,x≤c..
First, if f(a)=f(b), then comparing P(x,a) and P(x,b) gives a2=b2.
Putting x=y=0 gives
f(f(0)+f(0)2)=f(0),
so f(0)+f(0)2=0, and therefore f(0)∈{0,−1}.
Suppose first that f(0)=0. From P(x,0),
f(f(x))=f(x),
so the first observation gives f(x)=±x for each x.
Now f(y)2=y2, so the equation says
f(f(x)+y2)=f(x)+y2.
Thus every number of the form f(x)+y2 belongs to the set where f(t)=t. Hence this set is a ray, either all of R, [c,∞), or (c,∞), with c≤0 because 0 is fixed. This gives exactly the listed families.
It remains to exclude f(0)=−1. In this case, P(x,0) gives
f(f(x)+1)=f(x),
so ∣f(x)+1∣=∣x∣ for every x. Hence f(x)=x−1 or f(x)=−x−1 pointwise. Taking x=0 in the original equation gives
f(f(y)2−1)=y2−1.
But f(y)2−1=y2±2y, and applying f(t)=±t−1 to this expression cannot equal y2−1 for all real y. This contradiction removes the case f(0)=−1.
The listed functions are then directly checked.