This is a good question because it really hits on a subtle issue. It turns out that Johannes and Ben are both correct and incorrect at the same time unless we settle some very subtle issues. Let me explain.

There are really two things at issue here. The first is what is meant by the notation [X,Y] when X is not a CW-complex. Is it homotopy classes of maps? Or is it *weak* homotopy classes of maps? The other thing at issue is what is meant by a cohomology theory? Is it a functor which sends just homotopy equivalences to isomorphisms? or is it also required to send weak homotopy equivalences to isomorphisms?

These decisions determine who is right or wrong. Let X be the cantor set as in Ben's answer. As Ben rightfully points out the homotopy class of maps from X into the discrete space $\mathbb{Z}$ must factor through a finite quotient, while the singular cohomology is much larger. So Ben is interpreting [X, Y] to mean homotopy classes of maps. Weak homotopy classes of maps are more subtle. They are the morphisms in the derived category of spaces and are defined by taking equivalence classes of spans:

$$ X \stackrel{\sim}{\leftarrow} X' \rightarrow Y $$

where $X'$ ranges over spaces weakly homotopy equivalent to X. Equivalently you can replace X with any cofibrant replacement, like a CW-approximation. In the case of X= the Cantor set, the CW-replacement is a disjoint union of uncountably many points, and so the weak homotopy equivalence classes of maps does in fact agree with singular cohomology.

More generally if [X,Y] denotes weak homotopy classes of maps, then Johannes' statement is correct. The functor $[-, K(\mathbb{Z}, n)]$ always agrees with singular cohomology.

This brings us to the issue of what exactly a cohomology theory is supposed to be? If you ask an algebraic topologist they will usually tell you that a cohomology theory is *defined* so that it sends weak equivalences to isomorphisms (The Axiom of Weak Equivalence). If this is our definition, and [X,Y] denotes homotopy classes of maps and not weak homotopy classes of maps, then $[-, K(\mathbb{Z}, n)]$ *fails to be a cohomology theory*. But it is in good company Cech cohomology and sheaf cohomology also fail this litmus test, so many people outside of algebraic topology feel uncomfortable with this axiom.

However it is necessary for the uniqueness result of the Eilenberg-Steenrod axioms. The Axiom of Weak Equivalence implies that the cohomology theory is *determined* by its value on CW-complexes, and the rest of the axioms lock this down. Without the Axiom of Weak Equivalence there is very little control on what the theory assigns to spaces which do not have the homotopy type of CW-complexes.