Solution (source code)

= Solution

Put $M=\mathbb E[Y\mid\mathcal G]$. Expanding and using $\mathbb E[YM]=\mathbb E[M^2]$ gives
$$
\mathbb E[(Y-M)^2]=\mathbb E[Y^2]-\mathbb E[M^2].
$$
If $M\stackrel d=Y$, the right side is zero. Therefore $Y=M$ almost surely.