In Allen Hatcher, Algebraic topology, the following paragraph exists:
And I am wondering if in the sentence starting with "From a more formal viewpoint .....", I changed the codomain of the function $r$ to $A$ instead i.e. $r: X \rightarrow A $, how will this spoil the definition of retraction?
Thanks!

For the sake of giving this an answer:
If you have a function $r:X \rightarrow A$, then it does not make sense to speak of a function $r^2$; that is, $r \circ r$.
This is because the function $r$ is defined on the domain $X$, and not $A$.