Here is a structural proof, which follows from an old result of Clifford [1]. There is certainly a direct proof only using the given identities, but it might be more artificial.
Let $S$ be a semigroup satisfying the two identities
\begin{align}
(1) \quad &x^3 = x \\
(2) \quad &x^2y^2 = y^2x^2
\end{align}
First observe that, for every $x \in S$, $x^2$ is idempotent. Indeed,
$$
x^2x^2 = x^3x = xx = x^2.
$$
It follows by (2) that idempotents commute in $S$. On the other hand, (1) shows that $S$ is a completely regular semigroup, that is, every element of $S$ belongs to some subgroup of $S$. Indeed, every element $x$ belongs to the subgroup $H(x) = \{x, x^2\}$ of $S$.
It follows that $S$ is the union of these subgroups and every $\mathcal{H}$-class of $S$ is a (maximal) subgroup of $S$. Moreover, (1) shows that these maximal groups have exponent $2$ and hence are commutative (see for instance this answer for a proof).
The structure of completely regular semigroups with commuting idempotents is described in Theorem 3 of [1]. It says that $S$ is a semilattice of groups, in the following sense. The idempotents of $S$ form a semilattice $E$ and $S$ is the disjoint union of groups $G_e$, $e \in E$. If $e > f$, there is a morphism $\varphi_{e,f}:G_e \to G_f$ such that, if $e > f > k$, then $\varphi_{f,k} \circ \varphi_{e,f} = \varphi_{e,k}$. Now, the product on $S$ is defined as follows. If $g_e \in G_e$ and $h_f \in G_f$ are two elements of $S$ and if $k = ef$, then the product $g_eh_f$ is in $G_k$ and is computed as follows:
$$
g_eh_f = \varphi_{e,k}(g_e) \varphi_{f,k}(h_f)
$$
Now, in your case, since $ef = fe$ and since $G_k$ is a commutative group,
this product is commutative.
[1] A. H. Clifford, Semigroups admitting relative inverses, Ann. of Math. (2) 42 (1941), 1037--1049.