The sequence $(X_t, Y_t)_{t \geq 1}$ generated by the Gibbs sampler is a Markov chain with invariant distribution $f_{X,Y}$. The marginal sequences $(X_t)_{t \geq 1}$ and $(Y_t)_{t \geq 1}$ are Markov chains with invariant distributions $f_X$ and $f_Y$ respectively. By the ergodic theorem, as $N \to \infty$,
\begin{align*}
\frac{1}{N} \sum_{t=1}^N g(X_t, Y_t) \xrightarrow{a.s.} \mathbb{E}_{(X,Y)}[g(X, Y)].
\end{align*}