For $A,B\in \mathcal B(\mathbb R)$, using the hypothesis with $h=1_A$ and $g=1_B$, $$P\big((X\in A) \cap (Y\in B)\big) = P\big(X\in (A\cap B)\big).$$
Taking $A=\mathbb R$ yields $ \forall B\in \mathcal B(\mathbb R)$, $P(Y\in B) = P(X\in B)$, hence $X\stackrel{d}= Y$.
Consequently, for any bounded measurable $h,g$ we have
$$E\big(h(X)g(Y) \big) = E\big(h(X)g(X) \big) = E\big(h(Y)g(Y) \big)$$
and exchanging $h$ and $g$ we have additionally
$$E\big(g(X)h(Y) \big) = E\big(g(X)h(X) \big)$$
thus
$$E\big(h(X)g(Y) \big) = E\big(g(X)h(Y) \big) = E\big(h(X)g(X) \big) = E\big(h(Y)g(Y) \big)$$
so that $$E\big([g(X)-g(Y)][h(X)-h(Y)] \big) = 0.$$
Taking $g=h=\arctan$ yields $$E\big([\arctan(X)-\arctan(Y)]^2 \big) = 0,$$ hence
$\arctan(X)=\arctan(Y)$ a.s. and
$X=Y$ a.s.