I'm trying to give a complete solution, where the I try to expand on the very good hints given by Μάρκος Καραμέρης and Ivan Neretin to find out which primes are 'good' (see below).
First, as already mentioned and proved by the problem author, $n$ needs to be square free as a necessary condition, so we have to look only at
$$ n = p_1p_2\ldots p_k$$
with the $p_i$ being the (different) prime factors of $n$. For ease of formulation, let's call a number $n \in \mathbb N$ 'good' if the considered mapping is a bijection, otherwise we call $n$ 'bad'.
A bad number $n$ can be characterized in 2 ways: It means that there is an $y \in X$ that is not in the image of $f$, or, equivalently, that there are 2 different $x,y \in X$ with $x^3 \equiv y^3 \pmod n$.
Lemma 1: If any $p_i$ is bad, then $n$ is bad.
Proof: Since $p_i$ is bad, there exists a value $b \in \{0,\ldots,p_i-1\}$ such that the equation $x^3 \equiv b \pmod {p_i}$ has no solution. If the equation $x^3 \equiv b \pmod n$ had a solution, the same value $x$ would also be a solution of $x^3 \equiv b \pmod {p_i}$, since $p_i|n$. $\blacksquare$
Lemma 2: If all $p_i$ are good, then $n$ is good.
Proof: Choose any $m \in X$. Because $p_i$ is good, the equation $x^3 \equiv m \pmod {p_i}$ has a (unique) solution $m_i \mod p_i$: Any $x$ with $x \equiv m_i \pmod {p_i}$ will satisfy $x^3 \equiv m \pmod {p_i}$.
By the chinese reminder theorem, there is a number $x$ (unique $\mod n$) that will satisfy all the $k$ equations $x \equiv m_i \pmod {p_i}$ at the same time. That means it will also satisfy all the $k$ equations $x^3 \equiv m \pmod {p_i}$ at the same time, which implies $x^3 \equiv m \pmod n$. Since you can change $x$ freely $\mod n$, you can choose one $x \in X$, which proves that $n$ is good. $\blacksquare$.
Lemma 1 and Lemma 2 show that we can now restrict ourselves to study only prime numbers as $n$. As often done, I'll denote that prime by $p$.
Theorem : $p \equiv 1 \pmod 3$ $\iff$ $p$ is bad.
Proof: $\Rightarrow$: It is known that the multiplicative group $\mod p$ is cyclic, so there exists a $g$ (generating element) such that $g^{p-1} \equiv 1 \pmod p$, but that this is not true for any lower positive exponent. Since $p \equiv 1 \pmod 3$, $\frac{p-1}3$ is an integer and hence with $r=g^{\frac{p-1}3}$ we have $r^3 \equiv 1 \pmod p$, whith $r \neq 1 \pmod p$. This concludes the $\Rightarrow$ direction of the proof.
$\Leftarrow$: If $p$ is bad, then there exist $x,y$ with $x\neq y \pmod p$ such that $x^3 \equiv y^3 \pmod p$. Since $p$ is a prime, the only solution to $x^3 \equiv 0 \pmod p$ is $x \equiv 0 \pmod p$, so we canonot have $x^3 \equiv y^3 \equiv 0 \pmod p$ and hence we have $x,y \neq 0 \pmod p$. That means we can divide both sides by $y^3$ and get $\frac{x^3}{y^3} \equiv 1 \pmod p$, which means we have a $z=\frac{x}y \neq 1 \pmod p$ with
$$ z^3 \equiv 1 \pmod p$$
The order of $z$ in the multiplicatice group $\mod p$ is therefore a divisior of 3. Since $z\neq 1 \pmod p$, we get that the order of $z$ is 3, which implies that $3|(p-1)$, as $p-1$ is the order of the group. This concludes the final part of the proof of the theorem.$\blacksquare$
To sum up, a number $n$ is good iff it is the product of distinct primes that are not $\equiv 1 \pmod 3$.