If $X$ is a selfadjoint operator on a Hilbert space, then $X^2x=0$ iff $Xx=0$ because $X^2x=0\implies 0=\langle X^2x,x\rangle = \langle Xx,Xx\rangle=\|Xx\|^2$.
Therefore, if $X,Y$ are selfadjoint and $X^2Y^2=0$, it follows that $XY^2=0$. Taking adjoints gives $Y^2X=0$ and, hence, $YX=0$. Taking adjoints again gives the desired result that $XY=0$.