Suppose $n$ is not prime and let $n=p_1^{k_1}\cdots p_s^{k_s}$ be the canonical factorization of $n$. Then $p_1^{k_1}\cdots p_i^{k_i}X$ and $p_{i+1}^{k_{i+2}}\cdots p_s^{k_s}X$ are nonzero elements of $\mathbb{Z}/n\mathbb{Z}[X]$ whose product is $0$ so this is not a domain and therefore not a UFD.
Conversely, if $n$ is prime, then $\mathbb{Z}/p\mathbb{Z}[X]$ is a polynomial ring over a field and therefore a UFD.
The first direction really can be done anyway you want. If you note that $\mathbb{Z}/n\mathbb{Z}$ is not a domain and $\mathbb{Z}/n\mathbb{Z}\subset \mathbb{Z}/n\mathbb{Z}[X]$ then the latter cannot be a domain either (as it at least contains the zero divisors of $\mathbb{Z}/n\mathbb{Z}$).