It is a standard fact that if $X$ is a path-connected CW-complex, then: $$[X,K(G,n)] = H^n(X;G)$$ where:
- $G$ is an abelian group;
- $n>1$ is an integer;
- $K(G,n)$ is the Eilenberg-Maclane space;
- $[X,K(G,n)]$ is the set of homotopy classes of maps $X \to K(G,n)$;
- $H^n(X;G)$ is the $n$th singular cohomology of $X$ with coefficients in $G$.
For example, when $X = S^k$, LHS becomes $[S^k,K(G,n)] = \pi_k(K(G,n)) = \begin{cases} G & k=n \\ 1 & k \ne n \end{cases}$, and RHS becomes $H^n(S^k;G) = \begin{cases} G & k=0,n \\ 0 & k \ne 0,n \end{cases}$, (and obviously $0=1$).
Is there a counter-example when $X$ is not a CW-complex? So, is there a path-connected topological space $X$, abelian group $G$, and integer $n>1$, with $[X,K(G,n)] \ne H^n(X;G)$?
It is well-known that if $X$ is a paracompact Hausdorff space, then $[X,K(G,n)] \approx \check{H}^n(X;G)$ where $\check{H}^n$ denotes Cech cohomology. See
Morita, Kiiti. "Čech cohomology and covering dimension for topological spaces." Fundamenta Mathematicae 1.87 (1975): 31-52.
http://matwbn.icm.edu.pl/ksiazki/fm/fm87/fm8714.pdf
But in general Cech cohomology does not agree with singular cohomology. For example, if $W$ is the Warsaw circle (which is a compact path connected subset of the plane), then $\check{H}^1(W;G) = G$, but $H^1(W;G) = 0$.
Now observe $H^{k+1}(S^k W) \approx H^1(W)$ and $\check{H}^{k+1}(S^k W) \approx \check{H}^1(W)$, where $S^k$ denotes $k$-fold suspension.