Since $X$ and $Y$ are homotopically equivalent there are two maps $f:X \to Y$ and $g:Y \to X$ which composites are homotopic to the appropiated identity maps.
Now if I pick a representative of an element of $[X,Z]$ labeled as $h$, then I have $h\circ g$ as a representative of an element of $[Y,Z]$.
Equivalently, if I pick a representative of an element of $[Y,Z]$ labeled as $j$, then I have $j\circ f$ as a representative of an element of $[X,Z]$.
Is this sufficient to conclude?
You have the right idea, now you have to prove that you get mutually inverse bijections.
Formally, put $f^*: [Y,Z]\to [X,Z]$ and $g^*: [X,Z]\to [Y,Z]$ defined by $f^*([j]) = [j\circ f]$ and $g^*([h]) = [h\circ g]$ where $[h]$ denotes the homotopy class of a map $h$.
First you have to show that this is well-defined, but this is the well-know fact that composition is well-behaved with respect to homotopy.
Now $f^*(g^*([h])) = f^*([h\circ g]) = [h\circ g\circ f] = [h]$ since $g\circ f\simeq Id$. Likewise, $g^*(f^*([j])) = [j]$ because $f\circ g\simeq Id$.
Thus $f^*$ and $g^*$ are mutually inverse bijections.