Two conditions need to hold.
First, $Xg(Y)$ must be a random variable. It would suffice for $g$ to be a measurable function, because that guarantees $g(Y)$ is a random variable, whence $Xg(Y)$ is. However, that's an overly strong condition. To see why, consider (for example) the case where $X = Y.$ Let $h$ be a non-measurable function defined on the zeros of $X$ and define
$$g(y) = \left\{\begin{aligned} y,& & X\ne 0 \\ h(y), & & X = 0.\end{aligned}\right.$$
This $g$ is not measurable by construction, but $XY = Xg(Y)$ is measurable.
Consequently, we must only require that the function $Xg(Y)$ be a random variable, which is a subtle restriction on $g.$
Second, the set of functions $g:\mathbb R\to \mathbb R$ satisfying the first criterion form a vector space $V_{X,Y}.$ Given any two such functions $g_1$ and $g_2$ and two real numbers $\lambda_1$ and $\lambda_2,$ the function $$X(\lambda_1 g_1(Y) + \lambda_2 g_2(Y)) = \lambda_1 Xg_1(Y) + \lambda_2 Xg_2(Y)$$ is measurable because it is a linear combination of measurable functions.
Take any $g\in V_{X,Y}.$ There are three cases to consider: either $E[Xg(Y)]$ does not exist; it is infinite; or it is finite. Trivially $E[Xg(Y)] \ne 0$ in the first two cases. The third case forms a vector subspace $V^0_{X,Y}\subset V_{X,Y},$ as is straightforward to check (use linearity of expectation).
Assume $E[XY]\ne 0$ is finite.
Suppose $g\in V^0_{X,Y}.$ For every (finite) number $c$ define
$$g_c(y) = g(y) + cy.$$
These are all measurable functions and they are all in $V^0_{X,Y}$ because
$$E[Xg_c(Y)] = E[X(g(Y) + cY)] = E[Xg(Y)] + cE[XY]\tag{*}$$
is finite, being the sum of two finite values. Geometrically, this set of functions $$\langle g \rangle_Y = \{g_c\mid c\in\mathbb R\} = \{g(Y) + cY\mid c\in\mathbb R\}$$ is an affine line in $V^0_{X,Y}.$
Because $E[XY]\ne 0$ is finite,
$$c^*(g) = -E[Xg(Y)]\ /\ E[XY]$$
is defined, unique, and by $(*)$ assures
$$E[Xg_{c^*(g)}(Y)] = E[Xg(Y)] - \frac{E[Xg(Y)]}{E[XY]} E[XY] = 0.$$
Consequently,
when $E[XY]\ne 0$ is finite, every function $g$ in the punctured line $\{g_c\mid c\ne c^*(g)\}$ satisfies $E[Xg(Y)]\ne 0.$

This is a sketch of the vector space $V^0_{X,Y}.$ The identity function $\iota: y\to y$ is one of the vectors, shown as the red arrow. Some of the punctured lines parallel to $\iota$ are drawn for background. The set of "special" functions $g_{c^*(g)}$ for which $E[Xg_{c^*(g)}(Y)]=0$ has been removed, leaving the white trace. One random dot at the lower left represents a generic function $g.$ Its projection in the $\iota$ direction onto $g_{c^*(g)}$ is shown to its upper right.
In this picture of the situation,
the functions $g$ for which $E[Xg(Y)]\ne 0$ consist of all points not on the white curve.
The exact nature of the white curve depends on the joint distribution of the random variables $(X,Y).$ What we have seen is that it intersects each of the affine lines parallel to $\iota$ exactly once: they form a line bundle.
Finally, I haven't dealt with the possibility that $E[XY]$ is infinite. If there exists a nonzero measurable function $f$ for which $E[Xf(Y)]$ is finite and nonzero, we may employ $f$ in defining $g_c(y) = g(y) + cf(y)$ and proceed as before. Unfortunately, there needn't exist such an $h$ in general (although there usually is in any statistical application).
The assumptions $E[X] = 0 = E[Y]$ were never used. Unfortunately, they don't help us out of the problems with infinities: it is possible for these additional assumptions to hold, yet for $E[XY]$ to be infinite. For instance, let $X$ have a Student $t(3/2)$ distribution and $Y=X.$