The following answer is quite rough, and assume some acquaintance with permutation groups.
You can write $\{1,\dots,9\}$ as a disjoint union of cycles for $f$. For example, if $f(1)=3,f(3)=4,f(4)=1$, then $(1\,3\,4)$ is such a cycle, and we say its length is $3$. Then you can check that the smallest number $n>0$ such that $f^{\circ n}=\mathrm{id}_{\{1,\dots,9\}}$ is the least common multiple of the length of its cycles. From all the partition of $9$ (e.g. $(1,1,7),(2,2,2,3),\dots$), you can check that $(4,5)$ is the one maximizing this least common multiple, this latter being equal to $20$. Finally, since you want the smallest number $n>1$ such that $f^{\circ n}=f$, you have to add $1$ to $20$, thus leading to $21$.
\circmakes a composition circle. – Randall Aug 14 '20 at 15:10