Which $BG$s are also $K(\pi,n)$s? As a motivation for the question, note that $\mathbb{C}P^\infty$ is at the same time a $BU(1)$ and a $K(\mathbb{Z},2)$; therefore, $H^2(X,\mathbb{Z})$ classifies complex line bundles on a space $X$.
By the same line of arguments, $BO(1) = \mathbb{R}P^\infty = K(\mathbb{Z}/2\mathbb{Z},1)$, hence real line bundles are classified by $H^1(X,\mathbb{Z}/2\mathbb{Z})$.
Further examples, with a somehow trivial flavour, can be obtained as follows: for any discrete group $G$ we have $BG = K(G,1)$. From the opposite point of view, we could say that for any group $\pi$, $K(\pi,1) = B\pi_{disc.}$. This gives rise to a lot of examples and I wonder:

Can we classify the triples $(G,\pi,n)$ of sufficiently nice topological groups1) $G$, arbitrary groups $\pi$ and positive integers $n$ such that $BG = K(\pi,n)$?

1) Please replace sufficiently nice topological groups by whatever setting you can deal with such that the question is interesting. It would be nice to cover the classical compact Lie groups. It will depend on the setting which groups we want to consider isomorphic.
As Tyrone pointed out in the comments, the question is essentially equivalent to the question which topological groups are Eilenberg-MacLane spaces.
Here are some observations, resulting in the homotopical classification:


*

*If $G$ is commutative and discrete or an $E_n$-space, so that the $n$-th iteration $B^nG = B(B^{n-1}G)$ exists, then we have $K(G,n) = B^nG$ as shown here.

*As discussed in the comments to this question, if $BG$ and $BH$ are homotopy equivalent, then $G$ and $H$ are homotopy equivalent as H-spaces.


Combining these two observations, we conclude that if $BG = K(\pi,n)$, then, understanding $\pi$ as a discrete group, $G$ is H-space homotopy equivalent to $B^{n-1}\pi$. Thus, up to homotopy, we get the complete list as $(K(\pi,n-1),\pi,n)$, but I was hoping to get something finer.
 A: It's time to get this off the unanswered list; it was essentially answered in the comments. As user PVAL-inactive noted, a $K(\pi,n)$ is infinite-dimensional as soon as $n\geq 2$. Therefore, restricting to classical groups (hence, finite-dimensional manifolds) we may consider the question which of classical Lie groups are $K(\pi,1)$s or $K(\pi,0)$s.
Suppose $G$ is a $K(\pi,0)$.
Then $G\simeq \pi_{\text{disc.}}\cong \pi_0(G)$ and almost all the classical groups with normalised determinant are connected, in fact, all but $\mathrm{SO}(p,q)$ with $p,q\geq 1$, which has two components.
Since $\pi$ can be assumed to be non-trivial, we conclude that for those groups, $\pi$ has to be the group of order two.
For the real classical groups, not normalising the determinant results in a product of $\pi_0$ with $\mathbb{Z}/2\mathbb{Z}$.
Therefore, we get:


*

*The groups with two contractible components, $\mathrm{Spin}(1) = \mathrm{O}(1)\simeq\mathrm{GL}(1,\mathbb{R})$, which give a $K(\mathbb{Z}/2\mathbb{Z},0)$

*and $\mathrm{O}(1,1)$, which is a $K(\mathbb{Z}/2\mathbb{Z}\times\mathbb{Z}/2\mathbb{Z})$.


In particular, $B\mathrm{O}(1)$ is a $K(\mathbb{Z}/2\mathbb{Z},1)$, as noted in the question text, resulting in the fact that $H^1(X,\mathbb{Z}/2\mathbb{Z})$ classifies real line bundles, and (for what it’s worth) we see that $B\mathrm{O}(1,1)$ is a $K(\mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/2\mathbb{Z},1)$ and so $H^1(X,\mathbb{Z}/2\mathbb{Z}\times \mathbb{Z}/2\mathbb{Z})$ classifies $\mathrm{O}(1,1)$-principal bundles.
Now suppose $G$ is a $K(\pi,1)$.
Then $G$ is connected and $\pi_1(G) = \pi$.
Looking at the list reveals that the only possibility is $\pi = \mathbb{Z}$ and in fact we find
$\mathrm{SL}(2,\mathbb{R})$, $\mathrm{SO}(2)$, $\mathrm{SO}(2,\mathbb{C})$, $\mathrm{Sp}(2,\mathbb{R})$, $\mathrm{SU}(1,1)$, $\mathrm{SO}^{*}(2)$ and $\mathrm{SU}(1)$, all homotopy equivalent to $\mathrm{U}(1) = S^1$, hence a $K(\mathbb{Z},1)$, in accordance with $B\mathrm{U}(1)$ being a $K(\mathbb{Z},2)$ as noted in the question text.
