We study Gutzwiller-correlated wave functions as variational ground states for the two-impurity Anderson model (TIAM) at particle-hole symmetry as a function of the impurity separation ${bf R}$. Our variational state is obtained by applying the Gutzwiller many-particle correlator to a single-particle product state. We determine the optimal single-particle product state fully variationally from an effective non-interacting TIAM that contains a direct electron transfer between the impurities as variational degree of freedom. For a large Hubbard interaction $U$ between the electrons on the impurities, the impurity spins experience a Heisenberg coupling proportional to $V^2/U$ where $V$ parameterizes the strength of the on-site hybridization. For small Hubbard interactions we observe weakly coupled impurities. In general, for a three-dimensional simple cubic lattice we find discontinuous quantum phase transitions that separate weakly interacting impurities for small interactions from singlet pairs for large interactions.