Let $X$ be an $(n-1)$-connected CW complex with $\pi_n(X) = G$. By attaching cells of dimensions at least $n+2$, we obtain a CW complex $Y$ the same $(n+1)$-skeleton as $X$, but with $\pi_i(Y) = 0$ for $i > n$. For $i \leq n$, we have, by cellular approximation,
$$\pi_i(Y) = \pi_i(Y^{(n+1)}) = \pi_i(X^{(n+1)}) = \pi_i(X),$$ so $Y$ is a $K(G, n)$ with $X$ as a subcomplex.
If $M$ is a CW complex of dimension at most $n$, then
$$[M, X] = [M, X^{(n+1)}] = [M, Y^{(n+1)}] = [M, Y] = [M, K(G, n)] = H^n(M, G).$$
Now consider the case $X = BSU(2)$. As $\pi_i(BSU(2)) = \pi_{i-1}(SU(2)) = \pi_{i-1}(S^3)$, $BSU(2)$ is $3$-connected and $\pi_4(BSU(2)) = \mathbb{Z}$, so for a CW complex $M$ of dimension at most four
$$\operatorname{Prin}_{SU(2)}(M) = [M, BSU(2)] = [M, K(\mathbb{Z}, 4)] = H^4(M, \mathbb{Z}).$$
The isomorphism $[M , BSU(2)] \to [M, K(\mathbb{Z}, 4)]$ is given by $[f] \mapsto [\iota \circ f]$ where $\iota : BSU(2) \to K(\mathbb{Z}, 4)$ is the inclusion map.
As $\mathbb{Z} \cong \pi_4(K(\mathbb{Z}, 4)) \cong H_4(K(\mathbb{Z}, 4); \mathbb{Z})$, the identity map $\operatorname{id} : \mathbb{Z} \to \mathbb{Z}$ gives rise to an element of $\operatorname{Hom}(H_4(K(\mathbb{Z}, 4); \mathbb{Z}), \mathbb{Z})$ and hence an element $\alpha$ of $H^4(K(\mathbb{Z}, 4); \mathbb{Z})$. The isomorphism $[M, K(\mathbb{Z}, 4)] \cong H^4(M; \mathbb{Z})$ is given by $[g] \mapsto g^*\alpha$.
The composition of these two isomorphisms is an isomorphism $[M, BSU(2)] \to H^4(M; \mathbb{Z})$ given by $[f] \mapsto (\iota\circ f)^*\alpha = f^*(\iota^*\alpha)$. The map $\iota^* : H^4(K(\mathbb{Z}, 4); \mathbb{Z}) \to H^4(BSU(2); \mathbb{Z})$ is an isomorphism because $BSU(2)^{(5)} = K(\mathbb{Z}, 4)^{(5)}$. As $\alpha$ is a generator of $H^4(K(\mathbb{Z}, 4); \mathbb{Z})$, $\iota^*\alpha$ is a generator of $H^4(BSU(2); \mathbb{Z}) \cong \mathbb{Z}c_2$, so $\iota^*\alpha = \pm c_2$.
Therefore the isomorphism $\operatorname{Prin}_{SU(2)}(M) \to H^4(M, \mathbb{Z})$ constructed above is either $P \mapsto c_2(P)$ or $P \mapsto -c_2(P)$. Either way, we see that for a CW complex $M$ of dimension at most four, principal $SU(2)$-bundles over $M$ are completely determined by their second Chern class; moreover, every element of $H^4(M; \mathbb{Z})$ arises as the second Chern class of some $SU(2)$-principal bundle on $M$.