The conditions $m\neq2$ and $m$ prime are indeed necessary but not sufficient.
So, conversely, given an odd prime $m=p$ what is the condition for $I$ to be prime or equivalently for the ring $(\mathbb Z/p\mathbb Z)[X,Y]/(X^2+Y^2)= \mathbb F_p[X,Y]/(X^2+Y^2)$ to be a domain ?
Since $\mathbb F_p[X,Y]$ is a unique factorization domain, the condition is exactly that the polynomial $X^2+Y^2$ be irreducible in $\mathbb F_p[X,Y]$.
A little calculation (that I'll leave to you) shows that this is the case exactly if $-1$ is not a square in $\mathbb F_p$.
And finally, deciding whether $-1$ is a square modulo $p$ is a very classical question that you can look up in a textbook or solve for yourself, using the result that the multiplicative group $\mathbb F_p^*$ is cyclic (the answer involves the residue modulo $4$ of $p$) .