Solution by isache.
The solutions are
f(x)=x,f(x)=−x,f(x)=1−x.
First, f is injective: if f(a)=f(b), comparing P(x,a) and P(x,b) for some x with f(x)=0 gives a=b.
Suppose f(0)=0. From P(x,0),
f(xf(x))=x2,
and comparing x with −x gives f(−x)=−f(x). Also f(x)=0 for x=0.
Putting y=−x2/f(x) in P(x,y) gives
f(f(x)x2)=x.
Replacing x by f(x) and using injectivity yields
xf(f(x))=f(x)2.(1)
Also P(1,0) gives f(f(1))=1, so f(1)=±1.
If f(1)=1, then
f(f(x)+1)=x+1,f(f(x)−1)=x−1.
Hence f(x+2)=f(x)+2. Then P(2,x) gives f(2f(x))=2x, and using the shift by 2 gives f(x+1)=f(x)+1. Therefore f(f(x))=x, and (1) gives f(x)=±x pointwise. The shift f(x+1)=f(x)+1 rules out any nonzero point with f(x)=−x, so f(x)=x.
If f(1)=−1, the same argument gives
f(x+1)=f(x)−1,
and again f(f(x))=x, so f(x)=±x pointwise. This shift forces f(x)=−x for all x.
Now suppose f(0)=c=0. From P(0,0) and P(0,c2), we get c3=c, so c=±1, and f(1)=0. Then P(1,0) forces c=1. Thus P(0,x) gives
f(f(x))=x.
Comparing P(x,1) and P(f(x),1) gives
f(x)2−f(x)=x2−x,
so f(x)∈{x,1−x} for every x. Since f(0)=1 and f(1)=0, the pair {0,1} is swapped.
If f(a)=a and a=21, then P(a,0) gives
f(a2+a)=a2.
As every value is either fixed or reflected by x↦1−x, this forces a=−1 or a=21. Thus the only possible fixed point other than 21 is −1. But if f(−1)=−1, injectivity forces f(2)=2, and then applying the previous argument to a=2 is impossible. Hence no such a exists, and f(x)=1−x for every x.
All three listed functions are directly checked.