Solution by zok_g8d.
The solutions are exactly the functions obtained as follows. Choose a set C⊆R such that
0∈/C,x∈C⟹x2∈C,
and
x,y∈C⟹x2+y2∈C.
Then define
f(x)={x,0,x∈C,x∈/C..
We prove that these are the only solutions. From P(0,x),
f(f(x)2)=xf(x).
Putting x=0 gives f(f(0)2)=0, and then putting x=f(0)2 gives f(0)=0.
If f(a)=f(b)=0, then the equation above gives af(a)=bf(a), so a=b. Thus f is injective on the set where it is nonzero.
Let
C={x:f(x)=0}.
For x∈C, comparing
P(x,0):f(xf(x))=xf(x)
with
P(0,x):f(f(x)2)=xf(x)
and using injectivity on nonzero values gives xf(x)=f(x)2, hence f(x)=x. Therefore f has the displayed form.
Moreover, if x∈C, then P(x,0) gives f(x2)=x2, so x2∈C. If x,y∈C, then P(x,y) gives
f(x2+y2)=x2+y2,
so x2+y2∈C.
Conversely, any function built from such a set C works by a direct case check according as x and y lie in C.