An example of an infinite disjoint union $X = \bigsqcup_\alpha X_\alpha$ such that $H^n(X, G) \neq \bigoplus_\alpha H^n(X_\alpha, G).$

For an infinite disjoint union $$X = \bigsqcup_\alpha X_\alpha$$, it is at least intuitively clear why the homology of $$X$$ decomposes into a direct sum

$$H_n(X) \cong \bigoplus_\alpha H_n(X_\alpha),$$

since the singular chain groups $$C_n(X)$$ by definition contain only finite sums of singular simplices $$\sigma: \Delta^n \to X_\alpha$$, which corresponds to the finite sums of cycles on the right hand side.

However, Hatcher switches to using infinite products when he introduces Cohomology (for example, Example 3.14, and the section on axioms for Cohomology), and we instead have the relation

$$H^n(X) \cong \prod_\alpha H^n(X_\alpha).$$

Can someone provide an example where this isomorphism of Cohomology with the infinite product holds, but the infinite direct sum does not? I would prefer a non-category theory explanation if possible. Thanks!

If $$X$$ is a set equipped with the discrete topology then its cohomology is just $$H^0(X, A) \cong A^X$$ (the infinite product of $$X$$ copies of $$A$$). The natural map from the infinite sum $$\bigoplus_X A$$ to the infinite product $$A^X$$ is never an isomorphism once $$X$$ is infinite and $$A$$ has at least two elements. For example, if $$X = \mathbb{N}$$ and $$A$$ is at most countable then $$\bigoplus_X A$$ is countable but $$A^X$$ is uncountable.
Since $$C_n (X) = \bigoplus C_n(X_\alpha)$$, then $$C^n(X) = \textrm{Hom} (C_n(X), \mathbb{Z}) = \textrm{Hom} (\bigoplus C_n(X_\alpha), \mathbb{Z}) = \prod \textrm{Hom} (C_n(X_\alpha), \mathbb{Z}).$$ So for example if $$X = \mathbb{Z}$$ (with the discrete topology), then $$H^0(X) = C^0(X) = \prod_{n \in \mathbb{Z}} \mathbb{Z}$$.
$$C^0$$ (for example) gives all of the homomorphisms from $$C_0$$ to $$\mathbb{Z}$$, and this has to include maps which are nonzero on every summand in $$C_0$$; this is why $$C^0$$ has to be the direct product rather than the direct sum.