Solving the functional equation $f(n^2+m)=f(n+m^2)$

The answer is$$ f(x) = \begin{cases} a; & x \text{ odd}\\ b; & x \text{ even} \end{cases}, $$ where $a, b$ are constants.

First to verify that such $f$'s indeed satisfy the condition. For any $m, n \in \mathbb{Z}$, because $m^2 \equiv m \pmod{2}$ and $n^2 \equiv n \pmod{2}$, then either $m^2 + n$ and $m + n^2$ are both odd or both even. Thus either $f(m^2 + n) = a = f(m + n^2)$ or $f(m^2 + n) = b = f(m + n^2)$.

Next, suppose $f$ is any function satisfying the condition. For any $x \in \mathbb{Z}$, take $(m, n) = (x, 0)$, then $f(x) = f(x^2)$, which also implies $f(-x) = f(x^2) = f(x)$. Now take $(m, n) = (x - 1, 1)$, then $f(x) = f(x^2 - 2x + 2)$. Take $(m, n) = (-x + 1, 1)$, then $f(-x + 2) = f(x^2 - 2x + 2)$. Therefore,$$ f(x) = f(-x + 2) = f(x - 2). \quad \forall x \in \mathbb{Z} $$