Yes. Will Sawin's answer uses a topological fact about the unit circle in $\mathbb{R}^2$. Here is an answer replacing $\mathbb{R}$ with any field of characteristic not $2$.
First, working modulo $x^2+y^2-1$, we can multiply terms of $g$ with powers of $x^2+y^2$, so we can assume $g = g_{2k} + g_{2k+1}$ for some $k$, where each $g_i$ is homogeneous of degree $i$. For convenience write these as $g_0,g_1$.
Observe that
$$ f \equiv (g_0 + g_1)^2 \equiv (g_0^2(x^2+y^2) + g_1^2) + 2 g_0 g_1 \pmod{x^2+y^2-1}. $$
There is a polynomial $h$ so that
$$ f + (x^2+y^2-1)h = (g_0^2(x^2+y^2) + g_1^2) + 2 g_0 g_1 . $$
Write $h = h_0 + h_1$ where $h_0$ is all the terms of even degree and $h_1$ is all the terms of odd degree (these are not necessarily homogeneous).
The first case is if $f$ is homogeneous of odd degree. In this case
$$ f + (x^2+y^2-1)h_1 = 2 g_0 g_1, \qquad (x^2+y^2-1)h_0 = g_0^2(x^2+y^2) + g_1^2 $$
In the second equation the right hand side is homogeneous. The only way for the left hand side to be homogeneous is to have $h_0 = 0$. Then $g_0^2(x^2+y^2) + g_1^2 = 0$,
but $x^2+y^2$ is not a perfect square (or negative of a perfect square) outside of characteristic $2$. So it must be $g_0=g_1=0$, and then $f \equiv 0$.
If $f$ is homogeneous of even degree then
$$ f + (x^2+y^2-1)h_0 = g_0^2(x^2+y^2) + g_1^2, \qquad (x^2+y^2-1)h_1 = 2 g_0 g_1 $$
Since $x^2+y^2-1$ is irreducible outside characteristic $2$ (in characteristic $2$ it's equal to $(x+y+1)^2$) it must be either $g_0 \equiv 0$ or $g_1 \equiv 0$ modulo $x^2+y^2-1$.
So then $f \equiv g_1^2$ or $f \equiv g_0^2$. These are the same polynomials that Will Sawin's answer ends with.