Via the [Kan--Thurston theorem](https://www.sciencedirect.com/science/article/pii/0040938376900409?via%3Dihub) we have a map between K(G,1) and X inducing (co)homology isomorphisms. Now you either take the definition of group cohomology to be the cohomology of K(G,1), or as I view best, take the bar construction that shows the cohomology of K(G,1) is isomorphic to the algebraically-defined group cohomology (see Ken Brown's textbook).