Factorization of a map between CW complexes

I don't think you need the mapping cylinder or the CW model for this.

Start with the factorization $$ X \xrightarrow{i} Z_0 \xrightarrow{g} Y, $$

where $Z_0 = X$, $i = \Bbb 1_X$ and $g = f$. Obviously $i_*$ is an isomorphism on $\pi_j$ for $j \le n$. We will attach $k$-cells to $Z_0$ for $k \ge n + 1$ and extend $g$ to make $g_*$ an isomorphism on $\pi_j$ for $j \ge n + 1$, while keeping $i_*$ an isomorphism for $j \le n$. We will use $Z_k$ to refer to the result of attaching $k$-cells to $Z_{k-1}$.

Fix base points for $Z_0$ and $Y$.

We will start by making $g_*$ surjective on $\pi_{n+1}$. Just as in the construction of CW approximations, choose maps $\varphi_\alpha : S^{n+1} \to Y$ representing the generators of the group $\pi_{n+1}(Y)$. For each $\varphi_\alpha$, attach an $(n+1)$-cell via a constant map to the base point of $Z_0$. This gives us $Z_{n+1}$. Extend $g$ to $Z_{n+1}$ via the maps $\varphi_\alpha$. The resulting $g_*$ is surjective on $\pi_{n+1}$ by construction.

Since the pair $(Z_{n+1}, X)$ is $n$-connected, $i_*$ is still an isomorphism for $j < n$, and surjective for $j = n$. Since $Z_{n+1}$ is the wedge sum of $X$ with $(n+1)$-spheres, there is a retraction from $Z_{n+1}$ onto $X$. This makes $i_*$ injective on $\pi_j$ for all $j$. Thus, $i_*$ is still an isomorphism on $\pi_j$ for $j \le n$.

Now we will attach $k$-cells to $Z_{n+1}$ for $k > n + 1$ to make $g_*$ an isomorphism on $\pi_j$ for $j \ge n + 1$. Such cells won't affect homotopy groups for $j \le n$, and therefore $i_*$ will remain an isomorphism in these dimensions.

For each $k > n + 1$, inductively attach $k$-cells to $Z_{k-1}$ to make $g_*$ injective on $\pi_{k-1}$ and surjective on $\pi_k$, exactly as done in the construction of CW approximations. The end result is the desired factorization.