Let $f:Y\to Z$ be a map of spaces, which is a weak homotopy equivalence. If for all CW complexes $X$ the map $f_*:[X,Y]\to [X,Z]$ is a surjective, is it also injective?
I have a hunch that this should be the case since a homotopy $H:f_*(g_1)\simeq f_*(g_2)$ will have a preimage under the map $$f_*:[X\times I,Y]\to [X\times I,Z]$$ but on the other hand I don't see why this preimage is a homotopy $g_1\simeq g_2$.
With the revised question, the answer is yes. You don't even need to assume surjectivity: if $f: Y \to Z$ is a weak equivalence, then $f_*: [X,Y] \to [X,Z]$ is a bijection for any CW complex $X$. This is Proposition 4.22 in Hatcher's algebraic topology book.