Let $\mathsf{Grp}$ denote the Lawvere theory of groups. (For concreteness, let us say that $\mathsf{Grp}$ is presented by the generators
- $c : X \times X \rightarrow X$
- $e : 1 \rightarrow X$
- $i : X \rightarrow X$
together with the usual relations.)
Now suppose $f : X \times \cdots \times X \rightarrow X$ is an arrow of $\mathsf{Grp}.$ Suppose also that $f$ is a homomorphism, meaning that for every model $G$ of $\mathsf{Grp}$ in $\mathbf{Set}$, we have that the function $G(f) : GX \times \cdots GX \rightarrow GX$ is the forgetful image of a homomorphism $G \times \cdots \times G \rightarrow G.$
Is it true that $f$ is necessarily either $e : 1 \rightarrow X$ or $\mathrm{id}_X : X \rightarrow X$?
The correct statement is that an $f : X \times \cdots \times X \to X$ that is a homomorphism in the sense you described must either factor through $1$ or be a projection onto some factor.
Think of the Lawvere theory of groups as the opposite of the category of free groups on finitely many generators. Then such an $f$ corresponds to a groups homomorphism $F_1 \to F_n$, which is determined by the image $w$ of a chosen generator of $F_1$. Represent $w$ as a reduced word in the generators $x_1, \ldots, x_n$ of $F_n$.
Given a group $G$, the map $Gf : G^n \to G$ is given by subsititution into the word $w$, i.e., $Gf(g_1, \ldots, g_n) = w[x_1=g_1, \ldots, x_n=g_n]$. If this is to be a homomorphism, we must have $$Gf(g_1h_1, \ldots, g_nh_n) = Gf(g_1, \ldots, g_n) Gf(h_1, \ldots, h_n)$$ for any group $G$ and any $g_1, \ldots, g_n, h_1, \ldots, h_n$ in $G$.
Take $G$ to be free on $2n$ generators $g_1, \ldots, g_n, h_1, \ldots, h_n$. Simplify both sides of the displayed equation until they are reduced words in the $g_i$ and $h_i$ (for the RHS this is just plugging into $w$, for the LHS, you plug in and expand any powers $(g_ih_i)^k$). Now, the RHS is a word with the property that all $g_i$ occur before all $h_i$. The LHS does not have this property unless $w$ is either $1$ or just one of the $x_i$.