Solution 1:

The statement is not true. The group of integers $\mathbf Z$ is residually finite. On the other hand, consider the open sets $U_p\subseteq \mathbf Z$ defined by $U_p = p\mathbf Z$, where $p$ runs over the primes. Clearly $\{U_p\} \cup \{5 \mathbf{Z} +1\} \cup \{5 \mathbf{Z} -1\}$ is an open covering of $\mathbf Z$ (as any integer is either $\pm 1$ or divisible by some prime). But this covering has no finite sub-covering: by the Chinese Remainder Theorem, there is no finite set of primes such that each integer which is $\pm 2$ mod $5$ is divisible by one of those primes.

We can give a criterion. To say that $G$ is residually finite is to say that the canonical morphism $G \to \widehat{G}$ from $G$ to its profinite competion is injective. Thus, if $G$ is residually finite, $G$ embeds as a dense subgroup of the compact group $\widehat{G}$. Since $\widehat{G}$ is Hausdorff and compact, $G$ will be compact precisely when it is closed in $\widehat{G}$ - which is to say, precisely when $G=\widehat{G}$.

(Thanks to studiosus for pointing out my earlier mistake. My mistake lied in the silly statement that open subsets of profinite groups are closed - which is false. Open subgroups are closed, but open subsets need not be closed! For instance, the complement of a point in an infinite profinite group is obviously not closed.)

Solution 2:

I know it's several years late, but based on some of the comments on Bruno Joyal's answer, I thought it would be helpful to further clarify some details.

Suppose $G$ is a residually finite group. We consider $G$ as a topological group in the profinite topology. In the answer, it is stated that "$G$ embeds as a dense subgroup of $\hat{G}$". It is worth clarifying that this use of the word "embeds" is indeed in the topological sense.

Proposition. Let $f\colon G\to\hat{G}$ be the canonical embedding. Then $f$ is a homeomorphism between $G$ and $f(G)$ (with the subspace topology from $\hat{G}$).

Proof. It suffices to fix a coset $C$ of some normal finite-index subgroup $H$ of $G$, and find an open set $U\subseteq\hat{G}$ such that $f(G)\cap U=f(C)$. Viewing elements of $\hat{G}$ as sequences $(C_N)_{N\in\mathcal{N}}\in \prod_{\mathcal{N}}G/N$, where $\mathcal{N}$ is the collection of normal finite-index subgroups of $G$, we can take $U=\{(C_N)\in \hat{G}:C_H=C\}$.


So to simplify terminology, we view $G$ as a subgroup of $\hat{G}$, and the profinite topology on $G$ as the subspace topology induced from $\hat{G}$. The relevant result is:

Theorem. The following are equivalent.

  1. $G$ is compact in the profinite topology.

  2. $G$ is closed in $\hat{G}$.

  3. $G$ is open in $\hat{G}$.

  4. $G=\hat{G}$.

  5. The canonical embedding of $G$ into $\hat{G}$ is a homeomorphism.

Proof.
(1) implies (2). If $G$ is compact in the profinite topology then (by the Proposition) $G$ is a compact set in $\hat{G}$. Since $\hat{G}$ is Hausdorff, $G$ is closed.

(2) implies (4). Trivial, since $G$ is dense in $\hat{G}$.

(4) implies (5). Immediate from the Proposition.

(5) implies (1). Immediate from compactness of $\hat{G}$.

(4) implies (3). Trivial.

(3) implies (2). Any open subgroup of a topological group is closed.



Some final remarks motivated by the comments on the accepted answer.

  • In general, $G$ is not necessarily open in $\hat{G}$, and so the canonical embedding of $G$ into $\hat{G}$ is not necessarily an open map (this was asked in a comment by W4cc0).

  • Since $\mathbb{Z}\neq\hat{\mathbb{Z}}$, it follows from the Theorem that $\mathbb{Z}$ is not compact in the profinite topology (Bruno Joyal also gave an explicit demonstration). The same holds for any countably infinite residually finite group, since there are no countably infinite compact Hausdorff groups (see this link).

  • As pointed out by user 59363, it is not the case that $G$ is compact in the profinite topology if and only if $G$ is finite (which is claimed in a comment by Moishe Cohen). For example, $\mathbb{Z}_p$ is a topologically finitely generated pro-$p$ group, and hence $\widehat{\mathbb{Z}_p}=\mathbb{Z}_p$ (this follows from a result of Serre, which was generalized to any topologically finitely generated profinite group by Nikolov and Segal).