By Chern-Weil theory, the real Pontryagin classes $p_k \in H^{4k}(X, \mathbb{R})$ of a real vector bundle $V$ on a smooth manifold $X$ are determined by the curvature form of any connection on that bundle; in particular, if the curvature vanishes, then so do all of the $p_k$. Hence if any of the $p_k$ don't vanish, then $V$ does not admit a flat connection. (Note that all of the $p_k$ vanish if $\dim X \le 3$; Milnor's result regarding the case $\dim X = 2$ requires more difficult tools.)

If $V$ is taken to be the tangent bundle of $X$, then the first case where this happens is when $\dim X = 4$, where $p_1 \in H^4(X, \mathbb{R})$. If $X$ is closed and orientable then $p_1$ is nonzero iff $X$ has nonzero signature, by the Hirzebruch signature theorem. The simplest example of a $4$-manifold with nonzero signature is $\mathbb{CP}^2$; it follows that the tangent bundle of $\mathbb{CP}^2$ does not admit a flat connection.

6more comments