This is a statement about the homotopy category. Consider the following fact:
Let $X$ be an object in a category $C$ such that the corepresentable functor $h^X:C\to \operatorname{Set}$ factors through the forgetful functor $\operatorname{Grp}\to \operatorname{Set}$. Then these data precisely specify the diagrams you drew above but for natural transformations wrt the corepresentable functor $h^X$. By Yoneda, all of these natural transformations descend down to $C$ (so long as $C$ has enough coproducts).
So in particular, we know that in the homotopy category of based spaces $\operatorname{Ho}(\operatorname{Top}_\ast)$, the functor $\pi_1:\operatorname{Top}_\ast \to \operatorname{Grp}$ is corepresented by the corepresentable functor $h^{(S^1,\ast)}$ where $h^{(S^1,\ast)}(X,x)=[(S^1,\ast),(X,x)]=\pi_1(X,x)$, as desired.