Taking kimchi lover's suggestion, and assuming everything in sight is sufficiently differentiable, we have:
\begin{align*}
\partial_x[f(x)+f(y)&=f(g(x,y))]\\
f'(x)&=\frac{df(g(x,y))}{dg}\,g_x(x,y)\\
\partial_y\bigg[f'(x)&=\frac{df(g(x,y))}{dg}\,g_x(x,y)\bigg]\\
0&=\frac{d^2f(g(x,y))}{dg^2}\cdot g_y(x,y)\cdot g_x(x,y)+\frac{df(g(x,y))}{dg}\cdot g_{yx}(x,y).
\end{align*}
You can let $h(g)=df/dg$ and use the first-order linear formula, or separate out and integrate:
\begin{align*}
0&=\frac{dh}{dg}\,g_y\,g_x+h\,g_{yx}\\
\frac{dh}{dg}&=-h\,\frac{g_{yx}}{g_y g_x}\\
h&=C_1\exp\left(-\frac{g_{yx}}{g_yg_x}\,g\right).
\end{align*}
Special case: $g_{yx}=0.$ Here we have
$$\frac{dh}{dg}\,g_y\,g_x=0, $$
with different possibilities depending on which factor is zero. Suppose $g_x=0.$ Then $g(x,y)=g(y).$ But because $g(y,x)=g(x,y),$ we must have $g(x,y)=g(x).$ The only way this could happen is if $g$ is a constant. It would follow, then, that $f(x)+f(y)=f(\text{const}),$ the only solution being a constant, namely, $f(x)=0.$
On the other hand, if $dh/dg=0,$ with neither of $g_x$ or $g_y$ zero, then $h$ is a constant, and hence $f=C_1g+C_2.$
So, back to $g_{yx}\not=0:$ integrating with respect to $g$ yields
$$f(g)=-\frac{C_1 g_yg_x}{g_{yx}}\,\exp\left(-\frac{g_{yx}}{g_yg_x}\,g\right)+C_2.$$
You can absorb the overall minus sign into $C_1$ if you like.
Putting it all together:
$$f(g)=\begin{cases}0,\;& g_x=0\;\text{or}\;g_y=0 \\
C_1g+C_2, &g_{yx}=0,\; g_x\not=0,\;\text{and}\;g_y\not=0 \\
\frac{C_1 g_yg_x}{g_{yx}}\,\exp\left(-\frac{g_{yx}}{g_yg_x}\,g\right)+C_2, &g_{xy}\not=0\end{cases}.$$