$X$ has finite mean.
Of course, in general $\mathbb{E}(X^2)=\mathbb{E}(Y^2)$ does not imply $X=Y$.
I tried using the fact that $(\mathbb{E}(X|\mathcal{G}))^2=\mathbb{E}(X^2|\mathcal{G})-\text{Var}(X|\mathcal{G})$ and also $\mathbb{E}(X^2)=(\mathbb{E}(X))^2+\text{Var}(X)$, hence:
$\mathbb{E}((\mathbb{E}(X|\mathcal{G}))^2)=\mathbb{E}(\mathbb{E}(X^2|\mathcal{G})-\text{Var}(X|\mathcal{G})) = \mathbb{E}((\mathbb{E}(X))^2+\text{Var}(X)) = \mathbb{E}(\mathbb{E}(X^2)) $
So we can apply the Tower rule and linearity of expectation to get:
$\mathbb{E}(X^2)-\mathbb{E}(\text{Var}(X|\mathcal{G}))= (\mathbb{E}(X))^2+\mathbb{E}(\text{Var}(X)) $.
This is where I'm stuck. We could rearrange to get $\text{Var}(X)= \mathbb{E}(\text{Var}(X|\mathcal{G})) + \mathbb{E}(\text{Var}(X)) $
And so this implies that $\mathbb{E}(\text{Var}(X)) = \text{Var}(\mathbb{E}(X|\mathcal{G})) $ by the Law of Total Variance. I.e. $ \text{Var}(X)) = \text{Var}(\mathbb{E}(X|\mathcal{G}))$, but I don't think that this implies $X=\mathbb{E}(X|\mathcal{G})$?
We also need $X$ to be square-integrable in order for $\mathbb E[X^2]$ to make sense. I assume this is the case.
First, note that \begin{align*} \mathbb E\big[\mathbb E[X|\mathcal G]^2\big]=\mathbb E\big[\mathbb E[X|\mathcal G]\mathbb E[X|\mathcal G]\big]\underset{\spadesuit}{=}\mathbb E\bigg[\mathbb E\big[\mathbb E[X|\mathcal G]X\big|\mathcal G\big]\bigg]\underset{\heartsuit}{=}\mathbb E\big[\mathbb E[X|\mathcal G]X\big],\tag{$\star$} \end{align*} where $\spadesuit$ is due to the fact that $\mathbb E[X|\mathcal G]$ is $\mathcal G$-measurable (so it can be pulled inside the other conditional expectation) and $\heartsuit$ is the law of total expectation.
Now define $Y\equiv\mathbb E[X|\mathcal G]-X$. Clearly, $\mathbb E[Y]=0$, so $\operatorname{Var}[Y]=\mathbb E[Y^2]$. But \begin{align*} \mathbb E[Y^2]&=\mathbb E\big[\mathbb E[X|\mathcal G]^2\big]+\mathbb E[X^2]-2\mathbb E\big[\mathbb E[X|\mathcal G]X\big]\\ &=\mathbb E\big[\mathbb E[X|\mathcal G]^2\big]+\mathbb E[X^2]-2\mathbb E\big[\mathbb E[X|\mathcal G]^2\big]\\ &=\mathbb E[X^2]-\mathbb E\big[\mathbb E[X|\mathcal G]^2\big]\\ &=0, \end{align*} where the second equality comes from $(\star)$ and the last one from your leading assumption. Consequently, $Y$ (almost surely) equals $0$.