On the two-dimensional sphere $M=S^2$ where we define $U(1)\rightarrow M$ principal bundle, we can associate an integer to such bundle: \begin{eqnarray} N=\int_M\text{ch}_1, \end{eqnarray} which is the index of Dirac operator on two sphere.
I notice that such integer is simply the winding number of transition function on the equator classifying $\pi_1[U(1)]$. Also on higher dimensions such as $SU(2)\rightarrow S^4$, the similar thing happens as well.
However, for $U(1)\rightarrow S^4$, this index $\int_M\text{ch}_2$ can be nonzero while the homotopy group $\pi_3[U(1)]$ is trivial.
My question is the reason for the appearance and disappearance of such relationship between the integer number $\int_M\text{ch}_{l}$ and homotopy group $\pi_{2l-1}\left(G\right)$with spheres $M=S^{2l}$.
The index you are calculating is actually zero for $l > 1$.
For a principal $U(1)$-bundle $P \to M$, we have $\operatorname{ch}(P) = \exp(c_1(P))$. If $H^2(M; \mathbb{Z}) = 0$, then $c_1(P) = 0$ and therefore $\operatorname{ch}(P) = 1$, i.e. $\operatorname{ch}_k(P) = 0$ for $k > 0$. In particular, $\int_{S^{2l}}\operatorname{ch}_l(P) = 0$ for all $l > 1$.