I wonder whether this is true in the categories of groups, monoids, commutative algebras, associative algebras, Lie algebras?

A retract of a finitely generated free monoid is free even though submonoids need not be free. I don't know about the infinitely generated case. Edit: infinitely generated seems ok. The fg case I saw in an automata theory book but I see a general proof. Added: here is the proof. Let P be a projective monoid (retract of free). Since it is a submonoid of a free monoid it has a unique minimal generating set Y consisting of the elements which are irreducible. Consider the map from the free monoid on Y to P sending generator to generator. Since P is projective it must split. But since elements of Y are irreducible their only preimages are the corresponding generators in the free monoid. Thus the splitting is an inverse to the projection. Added: It seems to me the above proof works verbatim for free commutative monoids and more generally relatively free monoids in varieties containing all commutative monoids. Added: Theorem 7 of http://arxiv.org/pdf/math/9711202.pdf seems to imply retracts of free nonassociative algebras are free. 


The answer is yes in the category of groups. Suppose that $f: G \to H$ is a retraction with $G$ a free group. Then there is a homomorphism $g: H \to G$ such that $fg = \mathrm{id}_H$. Thus $g$ is injective and hence embeds $H$ isomorphically as a subgroup of $G$. But any subgroup of a free group is free, so $H$ must be free. The same proof works in the category of abelian groups also. Edit: the same proof will work anytime you have the theorem that a subobject of a free object is free, I think. I don't know if that is true in the other categories that you mention. Further edit: this property can fail even in very nice categories. For example, let $k$ be a field and consider the matrix algebra $M_n(k)$. In the category of finitely generated modules over $M_n(k)$, $M_n(k)$ itself is a direct sum of $n$ copies of $k^n$, but $k^n$ is not free over $M_n(k)$. 


A few months after the last activity on this question, Neena Gupta gave a proof that over a field $k$ of positive characteristic, a retract of a polynomial algebra need not be a polynomial algebra: http://arxiv.org/abs/1208.0483. In fact, she gives a counterexample to the cancellation problem: there is an algebra $A$ such that $A[t]$ is isomorphic to $k[x_1,x_2,x_3,x_4]$ but $A$ is not isomorphic to $k[y_1,y_2,y_3]$. Composing the isomorphism $k[x_1,x_2,x_3,x_4]\to A[t]$ with the evaluation map $A[t]\to A$ at $t=0$ expresses $A$ as a retract of $k[x_1,x_2,x_3,x_4]$. 

