I am trying to determine all the endomorphisms of the identity functor $\text{id}_{\text {Grp} }: \text {Grp}\rightarrow \text {Grp}$
I know :
-that the forgetful functor $F:\text {Grp}\rightarrow \text {Set}$ is representable
-The representing object is $\mathbb Z$
-Using the Yoneda lemma:$$\mathrm{Hom}(F,F) \cong \mathrm{Hom}(\mathrm{Hom}(\mathbb{Z},-),F) \cong F(\mathbb{Z}),$$
How do I use these facts to arrive to the thesis?
Note that the Yoneda Lemma only applies when talking about $\rm Set$-valued functors. However, the identity functor on $\rm Grp$ is evidently not $\rm Set $-valued.
In this particular case, a careful analysis of the objects involved yields the result in an elementary way. We start by unpacking what an endomorphism of the identity functor $\operatorname{id}_{\rm Grp}\colon{\rm Grp}\to{\rm Grp}$ actually is. By definition, this is a collection $$ (\alpha_G\colon G\to G)_{G\in{\rm Grp}} $$ of group homomorphisms. Among these groups is the group $G=\mathbb Z$. This group has two important properties:
This shows immediately, that there are $n$ distinct choices for the map $\alpha_{\mathbb Z}$, uniquely determined by the image of $1$. Fix now one such $n$, i.e. suppose that $\alpha_{\mathbb Z}(1)=n$. If we now let $g\in G$, we can consider the unique group homomorphism $\varphi_g\colon\mathbb Z\to G$ mapping $1$ to $g$. The associated naturality square reads $\require{AMScd}$ \begin{CD} \mathbb Z @>{\alpha_{\mathbb Z}}>> \mathbb Z \\ @V{\varphi_G}VV @VV{\varphi_G}V \\ G @>>{\alpha_G}> G \end{CD} and we deduce that $$ \alpha_G(g) =\alpha_G(\varphi_G(1)) =\varphi_G(\alpha_{\mathbb Z}(1)) =\varphi_G(n) =g^n\,. $$ Thus, if we fix $n\in\mathbb Z$ so that $\alpha_{\mathbb Z}(1)=n$, then all $\alpha_G\colon G\to G$ are uniquely determined as $g\mapsto g^n$. However, letting $G=F_2$ be the free group in two generators, shows that only $n=0,1$ produce group homomorphisms.
Thus, there are exactly two endomorphisms of the identity functor, one with all components the trivial group homomorphism and one with all components identities.
In the same way one can classify endomorphisms of $\operatorname{id}_{\rm Set}\colon{\rm Set}\to{\rm Set}$ or $\operatorname{id}_{{\rm Mod}_R}\colon{\rm Mod}_R\to{\rm Mod_R}$ for a commutative unital ring $R$. These and your example are computations of the center of a category (see also here).