Part of Birkhoff's HSP theorem for varieties of groups. This is part of Exercise 2.3.7 of Robinson's "A Course in the Theory of Groups (Second Edition)". According to  Approach0, it is new to MSE; well, except this, which is not what I'm looking for as it uses universal algebra, a topic I haven't studied in a long time.
The first part of the exercise is this:
Show that ${\rm Var}\, \mathfrak{X}$ is a variety.
A previous exercise in the set in Robinson's book, relevant to this exercise, is this:
Part of Birkhoff's theorem for varieties of groups in Robinson's book.
The Details:
Since definitions vary, on page 15, ibid., paraphrased, it states that

A subgroup $N$ of $G$ is normal in $G$ if one of the following equivalent statements is satisfied:
(i) $xN=Nx$ for all $x\in G$.
(ii) $x^{-1}Nx=N$ for all $x\in G$.
(iii) $x^{-1}nx\in N$ for all $x\in G, n\in N$.

The definition of a direct product is on pages 20 to 21, ibid.

Let $\{G_\lambda\mid \lambda\in\Lambda\}$ be a given set of groups. The cartesian (or unrestricted direct) product,
$$C=\underset{\lambda\in\Lambda}{{\rm Cr}}\, G_\lambda,$$
is the group whose underlying set is the set product of the $G_\lambda$s [. . .] and whose group operation is multiplication of components: thus
$$(g_\lambda)(h_\lambda)=(g_\lambda h_\lambda),$$
$g_\lambda, h_\lambda\in G_\lambda$. [. . .]
The subset of all $(g_\lambda)$ such that $g_\lambda=1_\lambda$ for almost all $\lambda$ [. . .] is called the external direct product,
$$D=\underset{\lambda\in\Lambda}{{\rm Dr}}\, G_\lambda,$$
[. . .] In case $\Lambda=\{\lambda_1,\dots,\lambda_n\}$, a finite set, we write
$$D=G_{\lambda_1}\times\dots\times G_{\lambda_n}.$$
Of course $C=D$ in this case.

On page 56, ibid.,

Let $F$ be a free group on a countably infinite set $\{x_1,x_2,\dots\}$ and let $W$ be a nonempty subset of $F$. If $w=x_{i_1}^{l_1}\dots x_{i_r}^{l_r}\in W$ and $g_1,\dots, g_r$ are elements of a group $G$, we define the value of the word $w$ at $(g_1,\dots,g_r)$ to be $w(g_1,\dots,g_r)=g_1^{l_1}\dots g_{r}^{l_r}$. The subgroup of $G$ generated by all values in $G$ of words in $W$ is called the verbal subgroup of $G$ determined by $W$,
$$W(G)=\langle w(g_1,g_2,\dots) \mid g_i\in G, w\in W\rangle.$$

On page 57, ibid.,

If $W$ is a set of words in $x_1, x_2, \dots$ and $G$ is any group, a normal subgroup $N$ is said to be $W$-marginal in $G$ if
$$w(g_1,\dots, g_{i-1}, g_ia, g_{i+1},\dots, g_r)=w(g_1,\dots, g_{i-1}, g_i, g_{i+1},\dots, g_r)$$
for all $g_i\in G, a\in N$ and all $w(x_1,x_2,\dots,x_r)$ in $W$. This is equivalent to the requirement: $g_i\equiv h_i \mod N, (1\le i\le r)$, always implies that $w(g_1,\dots, g_r)=w(h_1,\dots, h_r)$.
[The] $W$-marginal subgroups of $G$ generate a normal subgroup which is also $W$-marginal. This is called the $W$-marginal of $G$ and is written $$W^*(G).$$

On page 57, ibid.,

A [. . .] class of groups $\mathfrak{X}$ is a class - not a set - whose members are groups and which enjoys the following properties: (i) $\mathfrak{X}$ contains a group of order $1$; and (ii) $G_1\cong G\in\mathfrak{X}$ always implies $G_1\in\mathfrak{X}$.
[. . .] A group in a class $\mathfrak X$ is called an $\mathfrak X$-group.

On page 58, ibid.,

If $W$ is a set of words in $x_1, x_2, \dots $, the class of all groups $G$ such that $W(G)=1$, or equivalently $W^*(G)=G$, is called the variety $\mathfrak{B}(W)$ determined by $W$.

The Question:

If $\mathfrak X$ is any class of groups, define ${\rm Var}\,\mathfrak X$ to be the intersection of all varieties that contain $\mathfrak X$. Prove that ${\rm Var}\,\mathfrak X$ [. . .] consists of all images of subgroups of cartesian products of $\mathfrak X$-groups.

Thoughts:
By the first part of the exercise, ${\rm Var}\,\mathfrak X$ is a variety; by the earlier exercise, then, ${\rm Var}\,\mathfrak{X}$ is closed with respect to forming subgroups, images, and subcartesian products; so - I guess - we can conclude
$$\mathbf{H}(\mathbf{S}(\mathbf{P}(\mathfrak X)))\subseteq {\rm Var}\,\mathfrak X,\tag{1}$$
where:

*

*$\mathbf{H}(\mathfrak{Y})$ means "homomorphic images of the groups in the class $\mathfrak{Y}$ of groups";

*$\mathbf{S}(\mathfrak{Y})$ means "subgroups of the groups in the class $\mathfrak{Y}$ of groups"; and

*$\mathbf{P}(\mathfrak{Y})$ means "products of the groups in the class $\mathfrak{Y}$ of groups".

This notation, I gather, is from universal-algebra.
One problem I have here is in ensuring that $\mathbf{K}(\mathfrak Y)$ is a variety for each (relevant) $\mathfrak Y$ and for each (relevant) $\mathbf{K}$; another problem is that, wouldn't it be $\mathbf{H}(\mathbf{S}(\mathbf{P}({\rm Var}\,\mathfrak X)))\subseteq {\rm Var}\,\mathfrak X$?
To prove the reverse inclusion of $(1)$, I guess I could proceed as I would with a set theoretic inclusion: by supposing $G\in {\rm Var}\,\mathfrak X$ with the aim of proving $G\in \mathbf{H}(\mathbf{S}(\mathbf{P}(\mathfrak X)))$. Nothing springs out at me regarding how to do this, although I suppose I'd have to find a homomorphism $\varphi: G\to S$ (or is it $\psi: S\to G$?) for some subgroup $S$ of a product $P$ of $\mathfrak X$-groups.
Please help :)
 A: First, let me respond to your last couple paragraphs:
First, it will turn out that $${\bf HSP}(\mathfrak{X})={\bf HSP}(Var(\mathfrak{X}))=Var(\mathfrak{X}).$$ So your concern about ${\bf HSP}(\mathfrak{X})$ versus ${\bf HSP}(Var(\mathfrak{X}))$ is moot.
More seriously, in general none of ${\bf H}(\mathfrak{X})$, ${\bf S}(\mathfrak{X})$, or ${\bf P}(\mathfrak{X})$ will be a variety (it's only when we apply all three operators (and in that specific order!) that we're guaranteed to get a variety).
That said, you are correct that previous exercises imply ${\bf HSP}(\mathfrak{X})\subseteq Var(\mathfrak{X})$, so you only have to prove the reverse inclusion: that if $G\in Var(\mathfrak{X})$ then $G\in {\bf HSP}(\mathfrak{X})$.

So how do we do that?
You mention that you want to avoid using universal algebra, but actually nothing is easier in the concrete case of groups; the argument is exactly the same. So I've sketched the more general version here. The only significant point of departure from the OP is that I talk about equations rather than words; the translation between the two phrasings is automatic, but in my opinion thinking in terms of equations makes things much clearer.
Nicely enough we're actually going to be pretty explicit about this. Suppose $G\in Var(\mathfrak{X})$, that is, $G$ satisfies every equation true in each element of $Var(\mathfrak{X})$. The idea is to construe $G$ as a quotient of a "sufficiently large" free algebra in $\mathfrak{X}$ (note that "free" here means "free in the context of $\mathfrak{X}$"). Keeping in mind that "quotient" is the same as "homomorphic image," this gives us ${\bf  H}$; the remaining piece of the puzzle is seeing how building free algebras amounts to a combination of ${\bf P}$ and ${\bf S}$.
Specifically, we want to find in ${\bf SP}(\mathfrak{X})$ an algebra $A$ such that $A$ is generated by a set $B\subseteq A$ with $\vert B\vert=\vert G\vert$, and no equations hold between any tuple of elements of $B$ other than those which hold universally in all elements of $\mathfrak{X}$. We then argue that a bijection $B\rightarrow G$ extends uniquely to a surjective homomorphism $A\rightarrow G$, at which point we get $$G\in {\bf H}(\{A\})\subseteq {\bf HSP}(\mathfrak{X})$$ as hoped for.
(Incidentally, note that the only connection between $G$ and $A$ is in terms of cardinality; apart from its size, our description of $A$ only refers to $\mathfrak{X}$ itself. This foreshadows the neat fact that we'll have $Var(\{A\})=Var(\mathfrak{X})$; every variety is generated by a single algebra!)
The key idea for building $A$ is the following:

Let $\mathfrak{X}_G$ be the class of algebras in $\mathfrak{X}$ expanded by a constant symbol ${\bf c}_g$ for each $g\in G$. For each $n$-variable equation $E$ not satisfied by all elements of $\mathfrak{X}$ and any $g_1,...,g_n\in G$, there is some $X_{E, g_1,..,g_n}\in \mathfrak{X}_G$ such that $E({\bf c}_{g_1},..., {\bf c}_{g_n})$ does not hold in $X_{E, g_1,...,g_n}$.

Using this result and the fact that an equation holds of a tuple in a Cartesian product iff it holds "coordinatewise," we can build $A$ in two quick steps. First we build a really big product structure $U$:

 Let $(E_i)_{i\in I}$ be the set of equations not universally true across all structures in $\mathfrak{X}$, with $E_i$ having $n_i$-many variables. Let $$U=\prod_{i\in I}(\prod_{g_1,...,g_{n_i}\in G}X_{E_i, g_1,...,g_{n_i}}).$$

And then we take the part of $U$ we actually want to connect to $G$:

 Let $A$ be the subalgebra of $U$ generated by $\{\bf c_g^U: g\in G\}$.

A: In the question you reference, we showed that if $\mathbf{V}$ is a variety, then $\mathbf{V}$ is closed under taking arbitrary (cartesian) products, subgroups, and homomorphic images. Thus, for any class $\mathfrak{X}$, $\mathrm{Var}(\mathfrak{X})$ certainly contains $\mathbf{H}(\mathbf{S}(\mathbf{P}(\mathfrak{X})))$, since it contains $\mathfrak{X}$, hence $\mathbf{P}(\mathfrak{X})$, hence $\mathbf{S}(\mathbf{P}(\mathfrak{X}))$, hence $\mathbf{HSP}(\mathfrak{X})$.
So the key here is the other inclusion.  Following the pattern of similar constructions, the key is to show that $\mathbf{HSP}(\mathfrak{X})$ is already a variety. Given your definitions, this means showing that there is a set of words $W$ such that $\mathbf{HSP}(\mathfrak{X})$ consists precisely of all groups $G$ for which $W(G)=\{e\}$.
What could that set of words be? Well, we may as well throw in everything that could possibly be there. So we look at $\mathfrak{X}$,  and take every word that is satisfied by every group there.  It will be a bit conceptually easier to take all words that are identities for all groups in $\mathrm{Var}(\mathfrak{X})$, because we know that set is going to be "closed" (in the Galois connection sense; it will be a verbal subgroup of the free groups already).
(This follows the general proof of this result from George Bergman’s Invitation to General Algebra and Universal Constructions, which I just taught a course out of so it is fresh in my mind; it also would suggest itself if you’ve seen the construction of a free group as a subgroup of a “large enough” cartesian product; if you’ve never seen that construction, I encourage you to seek it out, perhaps in Bergman’s text. It’s pretty neat the first time you encounter it, and it has its roots in Freyd’s work on adjoint functors.)
So, let $W$ be the set of all words that are identities for every group in $\mathrm{Var}(\mathfrak{X})$; this is the fully invariant closure in the free group $F_{\omega}$ of countable rank of any set of words that determine $\mathrm{Var}(\mathfrak{X})$. We hope to show that $\mathbf{HSP}(\mathfrak{X})$ consists precisely of all groups that satisfy every words $w\in W$.
We know that $W(G)=\{e\}$ for every $G\in\mathbf{HSP}(\mathfrak{X})$, since $\mathbf{HSP}(\mathfrak{X})\subseteq \mathrm{Var}(\mathfrak{X})$ has already been established.
Note that if $w$ is a word not in $W$, then there exists a group $G\in\mathrm{Var}(\mathfrak{X})$ such that $w(G)\neq\{e\}$. But in fact we can do better: there must exist a group in the initial class $\mathfrak{X}$ for which $w(G)\neq\{e\}$. Indeed, if $w(G)=\{e\}$ for all $G\in\mathfrak{X}$, then the variety determined by $\{w\}$ contains $\mathfrak{X}$, and hence every group in $\mathrm{Var}(\mathfrak{X})$, which is the intersection of all varieties containing $\mathfrak{X}$, satisfies $w(G)=\{e\}$. Thus, in fact we see (as I alluded to above) that the set of all words satisfied by every group in $\mathrm{Var}(\mathfrak{X})$ is in fact equal to the set of all words satisfied by every group in $\mathfrak{X}$ (which makes sense...).
Now we want to show that every group that satisfies all words in $W$ is in $\mathbf{HSP}(\mathfrak{X})$. This is perhaps a bit tricky. The key is to use products of elements of $\mathfrak{X}$ as a proxy for "intersections" of sets of identities, in order to construct a "most general group generated by a set $Y$ that satisfies all words in $W$."
Let $G$ be a group such that $W(G)=\{e\}$ and $v\colon Y\to G$ be a $Y$-tuple of elements of $G$ that generate $G$ (you can take $Y$ to be the underlying set of $G$ if you want; it does not matter so long as the image generates $G$). Let $F(Y)$ be the free group on $Y$, and let $\mathbf{v}\colon F(Y)\to G$ be the morphism induced by $v$. I claim that $\mathbf{v}$ factors through a subgroup $H$ of a product $P$ of elements of $\mathfrak{X}$; if that is the case, then we will have
$$F(Y)\stackrel{f}{\longrightarrow}H\stackrel{g}{\longrightarrow}G,\qquad\text{with }H\leq P,$$
with $\mathbf{v}=g\circ w$. And since $\mathbf{v}$ is surjective, so is $g$, and so $G$ will be a homomorphic image of a subgroup of $P$, hence $G$ will lie in $\mathbf{HSP}(\mathfrak{X})$.
Note that because $\mathbf{v}(W(F(Y)))\subseteq W(G)$ by the functoriality of verbal subgroups, we know that $W(F(Y))\subseteq\ker(\mathbf{v})$.
Now, if $z$ is an element of $F(Y)$ that is not in $W(F(Y))$, then as we noted above there must exist a group $G_z\in \mathfrak{X}$ for which $z(G_z)\neq\{e\}$. In particular, there is a $Y$-tuple $Y\to G_z$ of elements of $G_z$ such that the induced map $w_z\colon F(Y)\to G_z$ has $w_z(z)\neq e$.
Define $P$ to be the group
$$P = \prod_{z\notin W(F(Y))}\!\! G_z\quad\in\mathbf{P}(\mathfrak{X}).$$
Let $f\colon F(Y)\to P$ be the unique map from $F(Y)$ into the product such that $\pi_z\circ f = w_z$.
What is the kernel of $f$? Well, because $P\in\mathbf{P}(\mathfrak{X})$, then $W(P)=\{e\}$; so we definitely know that $W(F(Y))\subseteq\mathrm{ker}(f)$. And by construction, if $z\notin W(F(Y))$, then $\pi_z\circ f(z) = w_z(z)\neq e$, so $z\notin\ker(f)$. Thus, $\ker(f)=W(F(Y))$.
(This is how we used a product as a proxy for an intersection, "cutting out" every element not in $W(F(Y))$.)
Now let us remember that $W(F(Y))\subseteq\ker(\mathbf{v})$, where $\mathbf{v}\colon F(Y)\to G$ was a surjective group homomorphism. Since $\ker(f)\subseteq \ker(\mathbf{v})$, it follows that $\mathbf{v}$ factors through $f$, so there exists $g\colon \mathrm{Im}(f)\to G$ such that $\mathbf{v}=g\circ f$. Thus, $G$ is isomorphic to a quotient of $\mathrm{Im}(f)\leq P$, and so $G$ is a homomorphic image of a subgroup of $P$, and thus lies in $\mathbf{HSP}(\mathfrak{X})$, which is what we wanted to prove.
Thus, every group $G\in\mathbf{HSP}(\mathfrak{X})$ satisfies $W(G)=\{e\}$, and every group $G$ with $W(G)=\{e\}$ lies in $\mathbf{HSP}(\mathfrak{X})$. Therefore, $\mathbf{HSP}(\mathfrak{X})$ is a variety of groups, as desired, and we are done. $\Box$

It is worth noting that the image of $F(Y)$ in $P$ that we constructed above, $\mathrm{Im}(f)$, is in fact the relatively free $\mathrm{Var}(\mathfrak{X})$-group on $Y$, which is mentioned in Noah's answer: it is a group that lies in $\mathrm{Var}(\mathfrak{X})$, and has a distinguished $Y$-tuple of elements $u\colon Y\to \mathrm{Im}(f)$, such that for every group $K\in\mathrm{Var}(\mathfrak{X})$ and every $Y$-tuple of elements of $K$, $v\colon Y\to K$, there exists a unique morphism $\phi\colon \mathrm{Im}(f)\to K$ such that $f\circ u = v$. (So it lies in $\mathrm{Var}(\mathfrak{X})$, and has the universal property of a free group on $Y$, but only with respect to groups in $\mathrm{Var}(\mathfrak{X})$; that's why it is only "relatively" free). This follows because the induced map $F(Y)\to K$ factors through $\mathrm{Im}(f)$ for the exact same reason that $\mathbf{v}$ did.
This way to construct relatively free groups (or even actual free groups) as "subgroups of a big product" comes from Freyd's General Adjoint Functor Theorem. There is a nice exposition of the construction (together with two other "classical" constructions of the free group for comparison) in Chapter 3 of George Bergman's An Invitation to General Algebra and Universal Constructions, mentioned above.
