Suppose that $C,D$ are two varieties (equational classes) and that $U:C\rightarrow D$ is the forgetful functor. Is it true that if this functor preserves coproducts and initial objects then it has a right adjoint?
I remember someone once told me this fact but I do not remember whom it was to ask for details. I just remember that I have been told that it follows from Freyd's criterion and some properties of varieties, but whenever I look at Freyd's criterion, it only talks about the existence of left adjoints and not right adjoints. Maybe this is easy, but I did not study the subject properly but need to use this result but I want to make sure it is true and understand some of its backgrounds.
I would appreciate any clarification/reference where I can find proof for this fact.
Yes, this is true. I claim first that if the forgetful functor $U:C\to D$ preserves coproducts, then it preserves coequalizers. Let $f,g:X\to Y$ be $C$-morphisms, let $\sim_C$ be the $C$-congruence relation they generate on $Y$ and let $\sim_D$ be the $D$-congruence relation they generate on $Y$. To show $U$ preserves coequalizers, we must show $\sim_C$ and $\sim_D$ are the same.
Let us denote the free $C$-algebra on $n$ generators $t_0,\dots,t_{n-1}$ by $F_n$. Note that $\sim_C$ is just the equivalence relation generated by saying that for any $\alpha(t_0,\dots,t_n)\in F_{n+1}$, any $x\in X$, and any $y_1,\dots,y_n\in Y$, $\alpha(f(x),y_1,\dots,y_n)$ is equivalent to $\alpha(g(x),y_1,\dots,y_n)$. So, it suffices to show that $\alpha(f(x),y_1,\dots,y_n)\sim_D \alpha(g(x),y_1,\dots,y_n)$ in this situation.
Let $i:F_{n+1}\to Y$ be the $C$-morphism sending the generators to $f(x),y_1,\dots,y_n$ and $j:F_{n+1}\to Y$ be the $C$-morphism sending the generators to $g(x),y_1,\dots,y_n$; it suffices to show that $hi=hj$ for any $D$-morphism $h:Y\to Z$ that coequalizes $f$ and $g$. Note that $F_{n+1}$ is a coproduct in $C$ of $n+1$ copies of $F_1$, and hence also in $D$ since $U$ preserves coproducts. So to show that $hi=hj$, it suffices to show their compositions with each coproduct inclusion $F_1\to F_{n+1}$ are the same. This is trivial for all the inclusions except the first one. For the first coproduct inclusion, the two maps we are comparing are just $hfk$ and $hgk$, where $k:F_1\to X$ is the $C$-morphism that sends the generator to $x$. These are equal since $h$ coequalizes $f$ and $g$.
Thus $U$ preserves coequalizers, and hence preserves all colimits. To show $U$ has a right adjoint, we now just have to verify the solution set condition of the general adjoint functor theorem (you mention being familiar with this theorem giving the existence of left adjoints, but you can get a criterion for the existence of right adjoints by just dualizing). Concretely, in this case, that just means we need the following: given a $D$-algebra $X$, there exists a cardinal $\kappa$ such that if $Y$ is any $C$-algebra and $f:Y\to X$ is a $D$-morphism, there is a $C$-algebra $Z$ of cardinality at most $\kappa$, a $C$-morphism $g:Y\to Z$, and a $D$-morphism $h:Z\to X$ such that $hg=f$. (Or more briefly, every $D$-morphism from a $C$-algebra to $X$ can be factored through a $C$-algebra of bounded cardinality.)
To prove this, suppose $Y$ is a $C$-algebra and $f:Y\to X$ is a $D$-morphism. Let $S$ be the set of $D$-morphisms $F_1\to X$. Then $f$ induces a function $\varphi:Y\to S$ as follows: given an element $y\in Y$, we get an associated $D$-morphism $F_1\to Y$ which we can then compose with $f$ to get an element of $S$.
Now consider the following diagram in $C$. The objects are $Y$, and a copy of $F_1$ for each element of $S$ that is in the image of $\varphi$. For each $y\in Y$, we have a morphism in the diagram from the copy of $F_1$ corresponding to $\varphi(y)$ to $Y$ which sends the generator to $y$. Let $g:Y\to Z$ be the colimit of this diagram in $C$ (which is also the colimit in $D$ since $U$ preserves colimits). That is, $g$ is the universal morphism that coequalizes the inclusions from $F_1$ of all pairs of elements $y,y'\in Y$ such that $\varphi(y)=\varphi(y')$. By definition of $\varphi$, $f$ coequalizes all such pairs of inclusions, so $f$ factors through $g$ (via a $D$-morphism $h:Z\to X$). On the other hand, note that $|Z|\leq |S|$, since pairs of elements of $Y$ that map to the same element of $S$ under $\varphi$ become equal in $Z$. Thus, taking $\kappa=|S|$, we have the desired factorization of $f$.
(Incidentally, there really is something nontrivial going on in verifying the solution set condition here--if you drop the assumption that $U$ preserves coproducts, then it may not satisfy the solution set condition! For instance, the forgetful functor from groups to sets does not, since there exist simple groups of arbitrarily large cardinality and nonconstant maps out of them cannot factor through any smaller group. Here's the step of the argument that would break down in that case: in order to factor $f$ through $g$, you need to know that $g$ is a colimit not just in $C$ but also in $D$, so you need to know that $U$ preserves colimits.)
Let me close with an explicit construction of the right adjoint, starting with an illustrative example. Let $C$ be the variety of sets with a unary operation and let $D$ be the variety of sets. Then the right adjoint $G:D\to C$ sends a set $X$ to the set $X^\mathbb{N}$ of sequences of elements of $X$, with unary operation given by the left shift operator (sending a sequence $(x_0,x_1,x_2,\dots)$ to $(x_1,x_2,x_3,\dots)$). (To relate this to the construction above, note that $X^\mathbb{N}$ is just the set of $D$-morphisms from the free $C$-algebra on one generator (i.e., $\mathbb{N}$) to $X$. Indeed, with some work you can extract this description of the right adjoint from the proof of the general adjoint functor theorem using the solution set given above.)
Why is this right adjoint to the forgetful functor? Well, suppose $Y$ is a set with unary operation $s$ and $f:Y\to X$ is a function. Then $f$ induces a map $g:Y\to X^{\mathbb{N}}$ sending each $y\in Y$ to the sequence $(f(y),f(s(y)),f(s^2(y)),\dots)$, and $g(s(y))$ is just the left-shift of $g(y)$. Conversely, any $C$-morphism $g:Y\to X^{\mathbb{N}}$ must have this form for a unique function $f$: if we define $f(y)$ to be the first term of the sequence $g(y)$, then the second term must be $f(s(y))$, the third term must be $f(s^2(y))$, and so on, because $g(s(y))$ is the left-shift of $g(y)$.
More generally, the right adjoint $G:D\to C$ can always be constructed explicitly by defining $G(X)$ as the set $S$ of $D$-morphisms $F_1\to X$ equipped with a $C$-algebra structure defined as follows. An $n$-ary operation of $C$ can be thought of as a $C$-morphism $F_1\to F_n$. Given $n$ elements of $S$, we get $n$ morphisms $F_1\to X$, which give a morphism $F_n\to X$ (since $F_n$ is a coproduct of $F_1$s in $D$, not just in $C$). We can then compose this with our morphism $F_1\to F_n$ to get a morphism $F_1\to X$, i.e. another element of $S$. Then, given a $D$-morphism $Y\to X$ where $Y$ is a $C$-algebra, the function $\varphi:Y\to S$ described in the proof above is exactly the adjoint $C$-morphism.