Here's a more conceptual alternative. Consider the three "eigenspaces" $G^0=\ker(f)$, $G^+=\{x\in G\mid f(x)=x\}$ and $G^-=\{x\in G\mid f(x)=-x\}$. It is easily checked that these are subgroups of $G$ and $f$ maps each of them into itself. More precisely, $f$ acts on $G^0$ as $0$, on $G^+$ as $1_{G^+}$ and on $G^-$ as $-1_{G^-}$. By asumption, $G=G^0\cup G^+\cup G^-$ and the claim is that in fact $G=G^0$ or $G=G^-$ or $G=G^+$.
Let's consider $f^2$. If $x\in G^+$, then $f^2(x)=f(f(x))=f(x)=x$. If $x\in G^-$, then $f^2(x)=f(f(x))=f(-x)=-f(x)=-(-x)=x$. In particular, it follows that $f^2$ is the identity on $G^+\cup G^-$ and the zero map on $G^0$. Thus, we see that there is a difference in behavior depending on whether $f$ is injective or not. We use these observations to first reduce the question to the injective case and then generalize.
Note that $f$ induces an endomorphism $\tilde{f}\colon\tilde{G}\rightarrow\tilde{G},\,x+\ker(f)\mapsto f(x)+\ker(f)$ of $\tilde{G}=G/G^0$. This is injective, for if $f(x)+\ker(f)=\ker(f)$, then $f^2(x)=0$. If $x\in G^+\cup G^-$, then $x=f^2(x)=0$, or $x\in G^0$. In any case, $x\in\ker(f)$, so $x+\ker(f)=\ker(f)$, proving injectivity.
Furthermore, $\tilde{f}$ also has the property that $\tilde{f}(\tilde{x})\in\{0,\tilde{x},-\tilde{x}\}$ for all $\tilde{x}\in\tilde{G}$. If we apply the observations from the first paragraph together with the injectivity of $\tilde{f}$, we can write $\tilde{G}=\tilde{G}^+\cup\tilde{G}^-$. However, it is well-known that a group cannot be the union of two proper subgroups, so $\tilde{G}=\tilde{G}^+$ or $\tilde{G}=\tilde{G}^-$, i.e. $\tilde{f}=\pm1_{\tilde{G}}$. Multiplying $f$ by $-1$ if necessary, we may WLOG assume that $\tilde{f}=1_{\tilde{G}}$.
Now, $\tilde{f}=1_{\tilde{G}}$ means that $x+\ker(f)=f(x)+\ker(f)$ for all $x\in G$, i.e. $f(x)-x\in\ker(f)$ for all $x\in G$, i.e. $f^2(x)=f(x)$ for all $x\in G$. If $x\not\in\ker(f)$, then this means $f(x)=f^2(x)=x$, so $x\in G^+$. It follows that $G=G^0\cup G^+$. For the same reason as before, $G=G^0$ or $G=G^+$, i.e. $f=0$ or $f=1_G$, as desired.