This question was asked before. But there is no formal answer and the comments don't help very much.
Show that $\langle X, Y\rangle \to \text{Hom}(\pi_n(X), \pi_n(Y)), \quad [f] \mapsto f_*,$ is a bijection if $X$ is an $(n - 1)$-connected CW complex and $Y$ is a path-connected space with $\pi_i(Y) = 0$ for $i > n$.(Hatcher 4.2.17)
I think I can prove that this map is surjective by Lemma 4.31 and the extension lemma. But the injectivity doesn't seem easy. Here is what I have got so far(you can ignore it if you have another good approach).
Suppose $f$ and $g$ are two map from $X$ to $Y$ such that $f_*=g_*$, we need to show that $f\simeq g$. Since X is $n-1$ connected, we may assume $X$ is obtained by attaching cells of higher dimension to $S:=\vee_\alpha S^n_\alpha $. The condition $f_*=g_*$ gives us a homotopy $F_S:f|S \simeq g|S$. I have an urge to use the homotopy extension property for $CW$ complexes. By homotopy extension property, there exist $F:f\simeq h$, where $h|S=g$. But I don't know why this $h$ should be equal(or homotopic) to $g$.
I believe that we should also use the condition $\pi_i(Y) = 0$ for $i > n$, and $f_*([h])=g_*([h])$ for higher dimension maps $h:S^{n+1}(\text{and}~ S^{n+2}, S^{n+3}...)\to X$ to extend $F$ to higher cells.(still no idea about how to defined the extension)
If you have a $k$-cell in $X$ and assume by induction that you have homotopy on the $k-1$ skeleton. Then this gives you an element of $\pi_{k}(Y)$. Think of it as a map from the tin can $S^{k-1}\times [0,1]\cup B_k\times\{0,1\}$ there on the side $S^{k-1}\times[0,1]$ you use the homotopy and on the top and bottom use $f$ and $g$. Now if $\pi_{k}(Y)=0$ then this is null homotopic and you can extend the homotopy.
Thus this works provided $n<k$ so the only problem is $k\leq n$ and this you have already, for any $n$-cell you have assumed that it is a sphere and thus the images under $f$ and $g$ represent the same element of $\pi_n(Y)$ and are thus homotopic.