Let $G$ be a (not necessarily finite) group with the property that for each subgroup $H$ of $G$, there exists a `retraction' of $G$ to $H$ (that is, a group homomorphism from $G$ to $H$ which is identity on $H$). Then, we claim :
$G$ is abelian.
Each element of $G$ has finite order.
Each element of $G$ has square-free order.
Let $g$ be a nontrivial element of $G$ and consider a retraction $T : G \to \langle{g\rangle}$ which is identity on $\langle{g\rangle}$. As $G/Ker(T)$ is isomorphic to $\text{Img}\langle{g\rangle}$, it is cyclic and so, it is abelian.
Other than this i don't know how to prove the other claims of the problem. Moreover, a similar problem was asked in Berkeley Ph.D exam, in the year 2006, which actually asks us to prove that:
If $G$ is finite and there is a retraction for each subgroups $H$ of $G$, then $G$ is the products of groups of prime order.