Proposition. Let $G,H$ be finite groups (abelian or not). Then the following implication holds: $$G\times G\cong H\times H \Rightarrow G\cong H.$$
In the case of $G,H$ both abelian, one can use the structure theorem (by looking at the invariant factors). Otherwise, I found an argument here, which is a bit unclear to me. I will rephrase it in this post:
Lemma. For a finite group $G$, the map ${\rm FinGr}\rightarrow \mathbb{N}, A\rightarrow |\text{Hom}(A, G)|$ (i.e. $A$ goes to the number of group homomorphisms from $A$ to $G$) uniquely determines $G$, up to isomorphism. Or equivalently, if $G_1$ and $G_2$ are two finite groups, such that for any finite group $A$ we have: $|\text{Hom}(A, G_1)|=|\text{Hom}(A, G_2)|$, then $G_1\cong G_2$.
Proof proposition: From $G\times G\cong H\times H$ we get $|\text{Hom}(A, G\times G)|=|\text{Hom}(A, H\times H)|$, for any finite group $A$. From the universal property of the direct product, we have: $|\text{Hom}(L, K\times K)|=|\text{Hom}(L, K)|^2$, for any groups $L,K$. We conclude that: $|\text{Hom}(A, G)|=|\text{Hom}(A, H)|$ for any finite group $A$. Using the previous lemma, we get the desired conclusion.
My question is: how do we prove this lemma? I tried some particular cases of $A$, cyclic, simple, but it doesn't bring much into light. (EDIT: My fault, I overlooked an answer to the lemma here, which is not trivial and I still have hard time understanding it).
Anyway, if you have a more ellegant/elementary approach to the original proposition, you are more than welcome to share it. Thank you in advance!