Is there a known example of a ring endomorphism $f: \mathbb{Z}[x_1, \ldots, x_n] \to \mathbb{Z}[x_1, \ldots, x_n]$ such that $f \circ f = f$ but whose image is not isomorphic to a polynomial ring?
My own interest in this has to do with better understanding the (categorical) Cauchy completions of Lawvere theories for some familiar types of algebraic objects; here we are dealing with the Lawvere theory of commutative rings. But apparently this type of problem is of interest to algebraists in the context of hard problems like the Jacobian conjecture and the cancellation problem, so there is a certain body of work out there already on related material.
From the literature I've scanned so far (articles by Costa, Shpilrain, Picavet, Gupta, and others), a lot of attention is paid to retracts of polynomial algebras over fields, but I'm having quite a hard time finding a clear statement for the case of polynomial algebras over $\mathbb{Z}$. One tantalizing lead was a statement by Picavet here: "We were motivated by an unsolved conjecture: a projective algebra of finite type over a field $A$ is a polynomial ring. An example by Costa shows that the statement is false if $A$ is not a field." I couldn't find a statement by Costa which treated every non-field $A$ (including $\mathbb{Z}$ in particular); I suspect Picavet meant that there exist non-fields $A$ for which the statement is false. An interesting example of such $A$ can be extracted from Gupta's later negative solution to the cancellation problem, as mentioned by Jeremy Rickard herehere at the MO discussion Is a retract of a free object free?Is a retract of a free object free?. (Actually, Gupta's constructions more significantly show that the statement is false for any field of positive characteristic, but this work can be used to derive some non-field examples as well.)
Akhil Mathew asked essentially the same question at Math.SE here, and got pointers to literature from Mariano Suárez-Alvarez, but I'm hoping to get something more definitive now.