See Theorem 3.6.3 here. The proof is quite long (4.5 pages) and would not be appropriate for reproduction at MSE. (I am well-aware of and, in general, agree with, the policy that one should not provide "link only" answer. However, in this case, link-only seems to be the only reasonable option.)
Edit: See also Proposition A.11 in Hatcher's "Algebraic Topology".
So that the answer is a bit more self-contained, here is a sketch of the proof given in Hatcher's book:
If $X_1 \xrightarrow{f_1} X_2 \xrightarrow{f_2} X_3 \to ...$ is a sequence of composable maps, let $T(f_1, f_2, \dots)$ denote the mapping telescope (aka homotopy direct limit). The proof uses the following three elementary facts about the mapping telescope:
- If $f_i \simeq g_i$ for all i, then $T(f_1, f_2, \dots) \simeq T(g_1, g_2, \dots)$;
- $T(f_1, f_2, f_3\dots) \simeq T(f_2, f_3\dots)$;
- $T(f_1, f_2, f_3\dots) \simeq T(f_2 f_1, f_4 f_3\dots)$.
Then:
$$T(fg, fg, fg\dots) \simeq T(f,g,f,g\dots) \simeq T(g,f,g\dots) \simeq T(gf,gf,gf\dots).$$
Since $gf \simeq \operatorname{id}$, $T(gf,gf\dots) \simeq T(\operatorname{id}, \operatorname{id}\dots) = X \times [0, \infty) \simeq X$.
On the other hand, $fg \simeq h : Y \to Y$ where $h$ is a cellular map (cellular approximation theorem), and then $T(fg,fg\dots) \simeq T(h,h\dots)$ is a CW-complex (because $h$ is cellular). So $X$ has the homotopy type of a CW complex.