This can be explained most cleanly, I think, in the language of model categories.
If a category $\mathcal{C}$ comes with a class $W$ of morphisms -- called the "weak equivalences" -- we might hope to form the "localization" $\mathcal{C}[W^{-1}]$ of $\mathcal{C}$, i.e. the initial category under $\mathcal{C}$ in which the weak equivalences are taken to isomorphisms, although note that this may not always exist. However, when the datum $W$ extends to a model structure on the category $\mathcal{C}$ (such as when $\mathcal{C}=\tt{Top}$), then we can recover $\mbox{Hom}_{\mathcal{C}[W^{-1}]}(X,Y) \cong \mbox{Hom}_{\mathcal{C}}(QX,RY)/\sim$, where $QX$ is a cofibrant replacement of $X$, $RY$ is a fibrant replacement of $Y$, and $\sim$ denotes the equivalence relation of homotopy. In the model category $\tt{Top}$, the CW-complexes are cofibrant and all objects are fibrant. Thus, if $Z \xrightarrow{\sim} Y$ is a weak equivalence, then composition with this map must induce an isomorphism
$$
(\mbox{Hom}_{\mathcal{C}}(X,Z)/\sim) \cong \mbox{Hom}_{\mathcal{C}[W^{-1}]}(X,Z) \xrightarrow{\cong} \mbox{Hom}_{\mathcal{C}[W^{-1}]}(X,Y) \cong (\mbox{Hom}_{\mathcal{C}}(X,Y)/\sim).$$
All of which is to say: The correct way to interpret this statement is to say that if $f:X \rightarrow Y$ is any map and $g:Z \xrightarrow{\sim} Y$ is a weak equivalence, then there exists a map $h:X \rightarrow Z$ such that $f \simeq g \circ h$, and moreover $h$ is unique up to homotopy.
Ah, I just realized I'm not distinguishing between objects of $\mathcal{C}$ and their images in $\mathcal{C}[W^{-1}]$. I hope this is clear nonetheless.
I recently gave a talk called "Model Categories for Algebraists, or: What's really going on with injective and projective resolutions, anyways?" in which I gave slightly more explanation than I did here about model categories and explained a number of ways in which model categories arise in algebra. If you're interested in a rather informal introduction to this stuff, you can find my (as of now only nearly complete) notes here. If you'd like to actually learn this material though, you should check out one of (a) Quillen's "Homotopical Algebra", (b) Hovey's "Model Categories", or (c) Hirschhorn's "Model Categories and their Localizations" (in decreasing order of my recommendation as an introduction to the theory).