We claim that f(x,y) is a polynomial in x and y of degree at most d.
It is obvious that every such polynomial satisfies the desired condition. To prove the converse, let f be a function satisfying the desired condition. Pick (d+2) straight lines ℓ1, ℓ2, …, ℓd+2 in R2 such that no two are parallel and no three are concurrent. Let the equation of ℓi be hi(x,y)=0, where hi is a linear polynomial.
For i<j, let (aij,bij) be the intersection of ℓi and ℓj, and consider the polynomial
φ(x,y)=1≤i<j≤d+2∑f(aij,bij)k=1k=i,j∏d+2hk(aij,bij)hk(x,y).
It is easy to see that φ(aij,bij)=f(aij,bij) for all i<j, and that degφ≤d. We shall show that φ(a,b)=f(a,b) for all a,b∈R.
We first make an observation: if ℓ is a line such that φ(a,b)=f(a,b) for at least (d+1) points (a,b) on ℓ, then φ(a,b)=f(a,b) for all points (a,b) on ℓ. Indeed, pick constants A, B, C and D such that t↦(At+B,Ct+D) parametrizes the line. Then, note that φ(At+B,Ct+D)−f(At+B,Ct+D) is a polynomial of degree at most d, and that it vanishes at least (d+1) points, so φ(a,b)=f(a,b) for all (a,b) on ℓ.
Now, for a fixed ℓi, note that f(aij,bij)=φ(aij,bij) for every j=i, so f(a,b)=φ(a,b) for all points (a,b) on ℓi from the claim. If (c,d) is a point not lying on any ℓi, then we can construct a line ℓ which passes through (c,d), does not pass through any (aij,bij), and is not parallel to any ℓi. Now f(a,b)=φ(a,b) with (a,b)=ℓi∩ℓ for various i, so f(a,b)=φ(a,b) for all (a,b) on ℓ. In particular, φ(c,d)=f(c,d). This completes the proof. □