When $n = p^k$, where p is prime and k is a positive integer
if $x^2 ≡ x$ (mod $p^k$), then $p^k$ divides $x^2-x = x(x-1)$, since $x$ and $x-1$ are coprime, $p^k$ divides either $x$ or $x-1$, so $x ≡ 0$ (mod $p^k$) or $x ≡ 1$ (mod $p^k$).
When n is not in the form of $p^k$,
on checking of counterexamples, $4^2 ≡ 4$ (mod $6$), where $4$ is not congruent to $0,1$ modulo $6$ and $6$ is a product of distinct primes.
Please suggest the general approach to prove that there exists solution other than $x ≡ 0,1$ (mod $n$) for this case.