As formulated, there are many counterexamples, although I suspect the OP has a slightly different question in mind.  For instance, let $Y$ be $\mathbb{P}^2$, let $X$ be the blowing up of the diagonal in $Y\times Y$ with either of its natural morphisms to $Y$, and let $Y'$ be  the nonreduced scheme from Exericse II.5.9 of Hartshorne's "Algebraic Geometry" (I hope that is the right number -- I only have a Russian edition in front of me).

If you assume that $Y$ is <b>affine</b>, then by Exercise II.8.6 (hopefully), there is a retraction, say $r:Y'\to Y$.  Thus you can pull back the smooth, projective morphism $f$ by $r$.