The if parts are straightforward enough. Every cyclic group is generated by one element, call it $g$, and thus every monoid homomorphism from a cyclic group is determined by where it sends $g$. If the codomain is the same cyclic group, then every element is $g^k$ for some $k$. Thus every monoid endomorphism of cyclic groups is a power function: $f(x) = f(g^k) = f(g)^k = g^{mk} = x^m$ where $x = g^k$ and $f(g) = g^m$. There are only two functions $\mathbb{Z}_2\to\mathbb{Z}_2$ such that $f(e) = e$ and both are monoid homomorphisms. Similarly, there are only two permutations of $\mathbb{Z}_3$ that fix $e$ and both are monoid homomorphisms.
The other way is a bit more interesting. First, the $\mathbb{Z}_2$ case. Let $g$ be an element of $M$ not equal to $e$. Then, by assumption, the function which sends everything but $e$ to $g$ is of the form $f(x) = x^n$ which is to say every element of $M$ other than $e$ satisfies $x^n = g$ for some $n > 0$. We easily have $g^n = g = x^n$ which if $M$ was a group would imply $g = x$ for all $x\neq e$ and we'd be done. To show that $M$ must be a group we consider the constantly $e$ function. Again, by assumption, we have $x^n = e$ for all $x$ for some $n > 0$. In fact, $n$ must be greater than $1$ otherwise $g = e$ contradicting the assumption of at least two elements. Therefore for every $x$, $xx^{n-1} = e$ and so $x^{n-1}$ is an inverse and all elements are invertible.
The same approach can't be used for the $\mathbb{Z}_3$ case since neither of the functions used above were necessarily permutations. Assume $M$ has $n+1$ elements and label the non-unit from $1$ to $n$. Let $\varphi$ cyclicly permute the $n$ non-units and fix $e$. Since $\varphi(g_1) = g_1^n = g_2 \neq g_1$, $n$ must be greater than $1$. $\varphi^n(x) = x^{n^n} = x$ for all $x$ where $\varphi^n$ means the $n$-fold application of $\varphi$. It's also clear that for all $x \neq e$, $x = g_1^k$ for some $k$, but since $n^n > n$, $e$ must also be $g_1^k$ for some $k$, thus $M$ is a cyclic group. Now use the permutation $\psi$ which swaps $g_1$ and $g_1^2$ (which are distinct and distinct from $e$ because there are at least $3$ elements) and fixes all other elements, then $\psi(x) = x^2$ and $\psi(\psi(x)) = x = x^4$ for all $x$. Thus we have a cyclic group of order $3$.