Let $(\Omega, \mathcal F, \mu)$ be a probability space, $\mathcal{G}$ a sub-$\sigma$-field of $\mathcal{F}$, and $X,Y:\Omega \to \mathbb R$ random variables such that $X=Y$ almost surely. This implies there is $N \in \mathcal F$ such that $\mu(N)=0$ and $X=Y$ on $N^c := \Omega \setminus N$. Assume that $X$ is $\mathcal G$-measurable. Fix $B \in \mathcal B(\mathbb R)$. Then $$ \{Y \in B\} := (\{X \in B\} \cap N^c) \cup (\{Y \in B\} \cap N). $$
Clearly, $\{X \in B\} \in \mathcal G$ because $X$ is $\mathcal G$-measurable. However, it is not necessarily true that $N \in \mathcal G$. As such, $Y$ is not necessarily $\mathcal G$-measurable.
Could you verify if my above understanding is fine?