I worked through this exercise myself. I apologize if I gave "too much" away, the proof of one of the directions in particular has a few somewhat intricate steps, so it would be hard to give merely an illuminating hint.
Let us set $b$ to be the degree of $f$.
The result $b|n \Rightarrow f|(x^{q^n}-x)$ is the more straightforward direction but this is the proof for sake of completeness. Let $f$ be an irreducible polynomial of degree $b$ in $K[x]$. Then $K[x]/f(x)K[x]$ is a field with $q^b$ elements. Then for each nonzero element $y(x) \in K[x]/f(x)K[x]$ the equation $$y^{q^b-1}(x) \equiv 1 \mod f(x)$$ holds, which gives $$y^{q^b}(x) - y(x) \equiv 0 \mod f(x).$$ So taking $y(x) = x$ this gives $$x^{q^b}-x \equiv 0 \mod f(x)$$ or $$x^{q^b} \equiv x \mod f(x).$$ So raising each side to the $q^{b}$-th power gives
$$x^{q^{2b}} = (x^{q^b})^{q^b} \equiv (x)^{q^b} \equiv x \mod f(x).$$
In fact, repeating this $j$ times gives
$$x^{q^{jb}} \equiv x^{q^{(j-1)b}} \equiv \ldots \equiv x^{q^b} \equiv x \mod f(x)$$
which gives $$x^{q^{jb}}-x \equiv 0 \mod f(x) \quad \forall j \in \mathbb{Z}^+.$$
So take $j = n/b$ to get $$x^{q^n}-x \equiv 0 \mod f(x)$$ or equivalently,
$$f(x)|(x^{q^{n}}-x).$$ So indeed, $b|n \Rightarrow f|(x^{q^n}-x)$. $\surd$
The other direction $f(x) | (x^{p^n}-x) \Rightarrow b | n$ is somewhat trickier. Let us suppose that $ n \mod b = r \not = 0$. We show the other direction by showing that $f$ cannot divide $x^{p^n}-x$.
Write $n= jb+r$. Then repeating the reasoning from the other direction gives
$$x^{p^n} = (x^{p^{jb}})^{p^r} \equiv (x^{p^{(j-1)b}})^{p^r} \equiv \ldots \equiv (x^{p^{b}})^{p^r} \equiv x^{p^r} \mod f(x),$$ or more concisely, $x^{p^n} \equiv x^{p^r} \mod f(x)$. Suppose that $f$ divides $x^{p^n}-x$. Then gives $$x^{p^n} \equiv x \mod f(x),$$ and so putting that together with the relation $x^{p^n} \equiv x^{p^r} \mod f(x)$ gives $$x^{p^r}-x \equiv 0 \mod f(x),$$ or equivalently, $f(x)|(x^{p^r}-x)$. We show next that this cannot be.
Now, on the one hand, as $K[x]/K[x]f(x)$ is a field, the polynomial $X^{p^r}-X$ has at most $p^r$ roots in $K[x]/K[x]f(x)$ equivalently
(A) there are at most $p^r$ polynomials $y(x) \in K[x]/K[x]f(x)$ that satisfy $y^{p^r}(x)-y(x) \equiv 0 \mod f(x)$.
However, one can also check that for any polynomial $Y \in K[X]$, the following holds because $K$ is characteristic $p$: $Y^{p^r}(X) = Y(X^{p^r})$. So if the relation $x^{p^r} \equiv x \mod f(x)$ holds, then $y^{p^r}(x) = y(x^{p^r}) \equiv y(x) \mod f(x)$ for each $y(x) \in K[x]/K[x]f(x)$, which gives that each of the $p^b$ polynomials $y(x) \in K[x]/K[x]f(x)$ satisfy $y^{p^r}(x)-y(x) \equiv 0 \mod f(x)$. However, as $r = n \mod b$ it follows that $p^b>p^r$, and so this contradicts (A). Thus
$f(x)$ cannot divide $x^{p^r}-x$ after all, if deg$(f) = b$ does not divide $n$. $\surd$