Garrett Ervin's answer to [When is $A$ isomorphic to $A^3$?](https://mathoverflow.net/q/10128#252553) mentions also some results on topological spaces. (Although the question was originally about abelian groups.)

The results mentioned there seem to answer your question - although I do hope that somebody can provide a more elementary solution. (The result from these papers have several additional requirements on the space $X$.)

In particular, the linked answer mentions the paper A. Orsatti and N. Rodino, *[Homeomorphisms between finite powers of topological spaces](https://doi.org/10.1016/0166-8641(85)90044-6)*, Topology Appl. 23 (1986), no. 3, 271--277; [MR858335](https://mathscinet.ams.org/mathscinet-getitem?mr=858335), [Zbl 0603.54009](https://zbmath.org/?q=an%3A0603.54009).

> Let $\lambda$ be an infinite cardinal number. It is proved that, for each positive integer $r$, there exists a compact connected homogeneous topological space $X$ of weight $\lambda$ such that $X^n$ is homeomorphic to $X^m$ iff $n\equiv m \pmod r$. The cardinality of the set of homeomorphism classes of compact connected homogeneous spaces with this property is exactly $2^\lambda$. Moreover every completely regular space of weight $\lambda$ is embeddable in a space of this type. 

Another paper with related results of this type is Věra Trnková: *[Products of metric, uniform and topological spaces](https://eudml.org/doc/17821).* Commentationes Mathematicae Universitatis Carolinae, vol. 31 (1990), issue 1, pp. 167-180; [MR1056184](https://mathscinet.ams.org/mathscinet-getitem?mr=1056184), [Zbl 0696.54009](https://zbmath.org/?q=an:0696.54009).

> For every triple of natural number $a$, $b$, $c$ there exists a metric space $X$, the $m$-th power and the $n$-th power of which are
>
 * homeomorphic iff $m\equiv n \pmod a$
 * uniformly homeomorphic iff $m\equiv n \pmod {ab}$
 * isomoteric iff $m\equiv n \pmod {abc}$
>  
This is a consequence of the main theorem proved in the present paper, where simultaneous representations of commutative semigroups by the products of metric, uniform and topological spaces are investigated.