Claim i. f(x) is injective.
Proof. Assume there exist two natural numbers x1 and x2 such that f(x1)=f(x2) and x1=x2. Now choose y and z such that y+z=t2−x1 then we have
f(y)+f(z)+f(x1)=a2
for some natural number a. Therefore,
f(y)+f(z)+f(x1)=f(y)+f(z)+f(x2)=a2,
so y+z+x2 must be square of some natural number s. Hence
∣x1−x2∣=∣t2−s2∣=0
and we have
∣t2−s2∣≥2∣t∣−1.
If we choose t large enough it gives us a contradiction.
Claim ii. For any x,y∈N we have f(x+1)−f(x)=f(y+1)−f(y).
Proof. Assume some arbitrary x0 and y0 with x0≥2, and choose z=t2−x0−y0 for some large t. Then
f(x0)+f(y0)+f(z)=a2,
and
f(x0−1)+f(y0+1)+f(z)=b2.
So we have
∣f(x0)+f(y0)−f(x0−1)+f(y0+1)∣=∣a2−b2∣.
Assume that f(x0)+f(y0)−f(x0−1)+f(y0+1)=0. If we choose z large enough, f(z) is a large number too (it's trivial because of the injectivity). But we know
∣f(x0)+f(y0)−f(x0−1)+f(y0+1)∣=∣a2−b2∣≥2∣a∣−1.
That means f(z) has an upper bound. Contradiction.
Claim ii implies that f(x) is a linear function so f(x)=ax+b and
a(x+y+z)+3b,
becomes a perfect-square if and only if
x+y+z,
does. That means at2+3b is a perfect-square for any t∈N. In particular a(at2+3b)+3b=t′2 hence
3ba+a=t′2−t2,
which is a contradiction unless 3ba+3b=0 (because the left hand side is either 0 or very big for big t). Now obviously a>0 and we get b=0, a=n2.