Why is the direct product of two groups $G_1 \times G_2$ too small to be their coproduct? We’re looking at the following definition in my class.

Definition. The coproduct $X_{1} \amalg X_{2}$ of $X_{1}$ and $X_{2}$, together with the morphisms $i_{j}: X_{j} \rightarrow X_{1}\amalg X_{2}$, is characterized by the following universal property: Given any object $Y$ with morphisms $f_{j}: X_{j} \rightarrow Y,$ there exists a unique $f: X_{1} \amalg X_{2} \rightarrow Y$ such that $f_{j}=f \circ i_{j}$.


In $G_1 \times G_2$, there exist two subgroups isomorphic to $G_1$ and $G_2$, namely the sets of elements $\{(g_1,e_2): g_1 \in G_1\}$ and $\{(e_1,g_2): g_2 \in G_2\}$, respectively. These two subgroups have the property that their members commute with each other: $(g_1,e_2) \cdot (e_1,g_2) = (g_1,g_2) = (e_1,g_2) \cdot (g_1,e_2)$.
The reason given for the direct product not being the coproduct is that, in a group $Y$ with maps $f_1: G_1 \to Y$ and $f_2: G_2 \to Y$, elements of $Y$ don’t commute with each other. I’m not yet able to derive this.
My understanding of the argument is that, given the property of the two subgroups above, I ought to be able to derive $f_1(g_1) \cdot_Y f_2(g_2) = f_2(g_2) \cdot_Y f_1(g_1)$, which would not be true for a general group $Y$ (unless $Y$ is abelian).
Now if I also assume $G_1 \times G_2$ to be the coproduct, I’d have:
$$f_1(g_1) \cdot_Y f_2(g_2) = (f \circ i_1)(g_1) \cdot_Y (f \circ i_2)(g_2) = f(g_1,e_2) \cdot_Y f(e_1,g_2)$$
It’s here that I don’t know how to keep going to get the relation above.
 A: Let $X_1, X_2$ be cyclic of order $2$ and let $x_i$ denote the non-trivial element of $X_i$. Let $Y$ be the set of permutations of $\Bbb Z$.
In particular, we have two elements $y_1,y_2\in Y$, given by $y_1(n)=-n$ and $y_2(n)=1-n$. Then $y_1\circ y_1=y_2\circ y_2=\operatorname{id}_{\Bbb Z}$, i.e., these are both of order $2$.
This allows us to define homomorphisms $f_i\colon X_i\to Y$ given by mapping $x_i\mapsto y_i$.
But $y_1( y_2(n))=n-1$ whereas $y_2(y_1(n))=n+1$, i.e., $y_1\circ y_2\ne y_2\circ y_1$ -- the elements do not commute in $Y$.
Hence neither may the elements $i_1(x_1)$ and $i_2(x_2)$ commute in $X_1\amalg X_2$. This shows that $X_1\amalg X_2$ cannot be just the direct product.

By the way, the subgroup of $Y$ that is generated by $y_1$ and $y_2$ (together with the above homomorphisms) does have the desired universal property. Can you show this?
A: As you observed, the main issue is that elements of $G_1$ always commute with elements of $G_2$ in $G_1\times G_2$, so it is not a free construction.
Notably, the direct product does coincide with the coproduct (satisfies its universal property) in the category of Abelian groups.
Choose specifically $X_1=X_2=\Bbb Z$, and consider the cocone $X_1\to X_1\times X_2\leftarrow X_2$ with $n\mapsto (n,0)$ and $n\mapsto (0,n)$.
Then a homomorphism $f_i:X_i\to Y$ basically just selects an arbitrary element $y_i$ of $Y$ (taking $y_i:=f_i(1)$), so in order for the diagram to commute, as $(1,0)$ and $(0,1)$ commute in $G_1\times G_2$, we would need that $y_1y_2=y_2y_1$ in $Y$:
If an $f:X_1\times X_2\to Y$ makes the diagram commutative, we have
$$f(1,0)=f(i_1(1))=f_1(1)=y_1\\
f(0,1)=f(i_2(1))=f_2(1)=y_2\\
f(1,1)=f((0,1)+(1,0))=f(1,0)f(0,1)=y_1y_2\\
f(1,1)=f((1,0)+(0,1))=f(0, 1)f(1,0)=y_2y_1\,.$$
So, there is no arrow $X_1\times X_2\to Y$ making the diagram of the universal property commutative, whenever $y_1,y_2$ are noncommutative in $Y$.
