Assume $n > 1$, and let $R=\mathbb{Z}/n\mathbb{Z}$.
For $x\in \mathbb{Z}$, let $\bar{x}$ denote the corresponding element of $R$.
Consider two cases . . .
Case $(1)$:$\;n$ is a power of a prime.
Let $n=p^k$, where $p$ is prime, and $k$ is a positive integer.
Suppose $\bar{x}$ is a non-unit of $R$.
Then we must have $p{\,\mid\,}x$.
\begin{align*}
\text{Then}\;\;&p{\,\mid\,}x\\[4pt]
\implies\;&p^k{\,\mid\,}x^k\\[4pt]
\implies\;&\overline{x^k}=0\\[4pt]
\implies\;&\bar{x}^k=0\\[4pt]
\end{align*}
hence $\bar{x}$ is a nilpotent element of $R$.
Case $(2)$:$\;n$ has at least two distinct prime factors.
Let $p,q$ be distinct prime factors of $n$.
Then $\bar{p}$ is not a unit of $R$, since $\gcd(p,n) = p > 1$.
Suppose $\bar{p}$ is a nilpotent element of $R$.
Then $\bar{p}^k=0$, for some positive integer $k$.
\begin{align*}
\text{Then}\;\;&\bar{p}^k=0\\[4pt]
\implies\;&\overline{p^k}=0\\[4pt]
\implies\;&n|p^k\\[4pt]
\implies\;&q|p^k\\[4pt]
\implies\;&q|p\\[4pt]
\end{align*}
contradiction.
Hence $\bar{p}$ is not a unit of $R$, and also not a nilpotent element of $R$.
Therefore, $R$ is such that every element is either a unit or nilpotent if and only if $n$ is a power of a prime.