If our Hilbert space can be separated to two (or more!) orthogonal subspaces $|\xi_x\rangle$ and $|\xi_y\rangle$, then every state in it can be written as a a direct product of states from this two orthogonal subspaces $$|\xi_x, \xi_y \rangle = |\xi_x\rangle \otimes |\xi_y\rangle$$
In this case, an operator $\hat{X}$ that acts only on states in the subspace spanned by $|\xi_x\rangle$ will act like the identity operator on all states in the orthogonal subspace spanned by $|\xi_y\rangle$, and likewise for an operator $\hat{Y}$ that acts only on states in the subspace spanned by $|\xi_y\rangle$.
From here, it is clear to see that for every state $$\hat{X} \hat{Y} |\xi_x, \xi_y\rangle = \hat{Y} \hat{X} |\xi_x, \xi_y\rangle$$
As this is true for every state, they commute.