The real answer came already from ajotatxe in the comments: There is no possible way to do this if $X$ has a prime factor that $n$ does not contain. No matter how many times ($k$) you make throws, you cannot put the resulting, equally probable $n^k$ sequences into $X$ bins with equal number of sequences in each bin.
What I like to elaborate on are 2 more things:
- The misconception shown in the example, and
- a way to do this, even if it might in theory take an unbounded number of throws.
1) Throwing a 6-sided dice will on average give you a $3.5$. If you throw one a hundred times, you are much more likely to come up with a sum near $350$ thnt with a sum near $100$ or $600$, the minimal and maximal values. That's because for a sum of $100$ all $100$ throws must be $1$, an obviously very unlikely outcome, where for a sum of $350$, you can have lots of any number from $1$ to $6$.
2) What you can do in your example (n=6, X=10) is the following: Throw your dice twice, writing down the result of the first throw, and writing down an additional $0$ if you trow $1-3$ on the second throw or a $6$ when you throw $4-6$ on the second throw. It's easy to see now that if you add the two numbers (your first throw and what you wrote down as result of the second throw), that you get a number between $1$ and $12$, uniformly distributed in that range.
If you got a number between $1$ and $10$, take this as you random number. If you get an $11$ or $12$, start over from the beginning (2 throws). This might in theory take you an unbounded number of rethrows, but in practice the probability of that goes to 0 fast.