Family of $p$-groups closed under products and subgroups: closed under quotients? Let $p$ be a prime, and let $\mathcal{U}$ be a family of finite $p$-groups such that

*

*Any group isomorphic to a group in $\mathcal{U}$ is also in $\mathcal{U}$

*Any product of groups in $\mathcal{U}$ is also in $\mathcal{U}$

*Any subgroup of a group in $\mathcal{U}$ is also in $\mathcal{U}$.

Is it automatically true that any quotient of a group in $\mathcal{U}$ also lies in $\mathcal{U}$?  This seems unlikely but I could not think of a counterexample.  (I tried various things involving dihedral groups and generalised quaternion groups, but did not go much beyond that.) Here is an initial result:
Lemma: if $A$ is abelian and is a quotient of a group $G\in\mathcal{U}$, then $A\in\mathcal{U}$.
Proof: we can write $A$ as a product of cyclic groups $C$.  As $\mathcal{U}$ is closed under products, it will suffice to prove that $C\in\mathcal{U}$.  Choose an element $g\in G$ that maps to a generator of $C$.  Then $g$ generates a cyclic subgroup $C'\leq G$ whose order must be a multiple of $|C|$.  It follows that $C'$ contains a subgroup $C''$ isomorphic to $C$.  As $\mathcal{U}$ is closed under subgroups and isomorphisms, it follows that $C\in\mathcal{U}$. ☐
 A: No. Fix an odd prime $p$. Let $H_p$ be a non-abelian group of order $p^3$ and exponent $p$ (this is unique to isomorphism).
Let $\mathcal{C}_p$ be the class of $p$-groups not containing any subgroup isomorphic to $H_p$. Then $\mathcal{C}_p$ is stable under taking subgroups (obvious) and direct products (easy because $H_p$ has a unique minimal normal subgroup).
Then it is enough to show that $H_p$ is quotient of some group in $\mathcal{C}_p$. Let $G_p$ be the free group on 2 generators in the variety of groups satisfying that $x^{p^2}=[y,z^p]=[[x,[y,z]]=1$ for all $x,y,z$, so $H_p$ is a quotient of $G_p$. It is enough to show that $G$ has no subgroup isomorphic to $H_p$. Indeed, $G_p$ has order $p^5$, and it is easy to check ($*$) that all elements in $G_p$ of order $p$ commute; hence it does not contain any copy of $H_p$.
($*$) I see it by writing $G_p$ as a Lie algebra over $\mathbf{Z}$ using Malcev-Lazard correspondence, namely the free Lie algebra over $\mathbf{Z}$ satisfying the laws $p^2x=p[y,z]=[x,[y,z]]=0$ for all $x,y,z$. It's quotient of the Heisenberg Lie algebra over $\mathbf{Z}/p^2\mathbf{Z}$ (which is the free one in the variety of laws $p^2x=[x,[y,z]]=0$), which has order $p^6$, by the subgroup of order $p$ in its center, hence has order $p^5$ ("basis" $(u,v,w)$ with $p^2u=p^2v=pw=0$, $[u,v]=w$), and precisely the set of elements killed by $p$ is an $p$-elementary abelian subgroup of order $p^3$, with "basis" $(pu,pv,w)$.
A: This is more or less the same as YCor's answer but perhaps more elementary.  Let $p$ be an odd prime, and let $\mathcal{U}$ be the class of $p$-groups in which all elements of order $p$ commute.  This is clearly closed under isomorphisms, products and subgroups.  Now let $G$ be the group of matrices over $\mathbb{Z}/p^2$ of the form
$$ g = \left[\begin{array}{ccc} 1&u&v \\ 0&1&w \\ 0&0&1 \end{array}\right], $$
and let $\overline{G}$ be the corresponding group over $\mathbb{Z}/p$.  In $G$ we find that $g^p=1$ iff $u,v,w\in p.\mathbb{Z}/p^2$, and it follows easily that $G\in\mathcal{U}$.  In $\overline{G}$ we find that all elements satisfy $g^p=1$, and so $G\not\in\mathcal{U}$.  There is an evident surjective homomorphism $G\to\overline{G}$, so $\mathcal{U}$ is not closed under quotients.
