Yes they are equivalent, given some very general assumptions on $g(\cdot)$, and you can prove this by the law of large numbers.
Lets consider the simpler case of a single discrete variable $X$ first. We want to show that the expectated value of $X$ can be approximated by a mean of samples from $X$. Generalising this to your problem is simple.
Let $\mathbb{E}(X) = \sum_{i=1}^N p_i X_i = \mu$ and $V(X) = \mathbb{E}((X-\mu)^2) = \sigma^2$. These are just definitions of the mean and variance. Now let
$S_n = \sum_{n=1}^{N} X_n$
for some finite $N$. What we want to show is that $\frac{S_n}{N} \to \mu$ as $N \to \infty$.
To show this consider $V(S_n)$. Since the variance of the sum of independent random variables is the same as the sum of their variance and the process generating $X_i$ is constant and samples generated are indepdendent, the variance of the sum is just $n$ times to variance of one variable i.e.
$V(S_n) = n\sigma^2$
equivalently
$V(\frac{S_n}{n}) = \sigma^2$
note also that from the defintion of expectation follows that
$\mathbb{E}(\frac{S_n}{n}) = \mu$
Chebyshevs inequality states that:
$P(|X-\mu| \geq \epsilon) \leq \frac{V(X)}{\epsilon^2}$
Therefore
$P(|\frac{S_n}{n} - \mu|\geq\epsilon) \leq \frac{\sigma^2}{N\epsilon^2} $
since $\epsilon$ (i.e. your target accuracy) is fixed this will tend to 0 as $N\to \infty$.
This is easily applied to your problem by considering the variable $Z$ with distribution $P(Z) = P(Y,X,g(X)) = P(Y|X) \cdot P(g(X)|X) \cdot P(X)$. You can sample $Z$ as you have a process for sampling $X$ and $Y$ and calculating $g(X)$. The key assumption I mentioned above, on $g(\cdot)$ is that it is such that $P(Z)$ has finite variance.