Suppose $A\times Y$ is a retract of $X\times Y$. We want to show that $A$ is a retract, which means finding a continuous function $f:X\to A$ such that $f|_A=\operatorname{id}_A$. Since $A\times Y$ is a retract of $X\times Y$, we have a continuous function $r:X\times Y\to A\times Y$ such that $r|_{X\times Y}=\operatorname{id}_{A\times Y}$. Since $Y$ is nonempty, we can find $y_0\in Y$. Then define $f(x)=\pi_1(r(x,y_0))$ for every $x\in X$, where $\pi_1:X\times Y\to X$ denotes the projection. Verify that $f$ is continuous and that it is a retraction.
Conversely, suppose $A$ is a retract of $X$. Then there exists a retraction $r:X\to A$. Can you think of a way to define a retraction $f:X\times Y\to A\times Y$? Let me know if you get stuck and I'll add more.