I will explain briefly, not providing a full proof. Consider a collection of particles whose position vectors r_a and momenta p_a are both bounded (i.e. they remain finite for all values of the time). The virial theorem is -in a more general case- an expression about the average kinetic energy of the system of the forementioned particles. Specifically it is:
<T> = -(1/2) * <Σ F_a*r_a> (1)
T = total kinetic energy
Σ = summation over a = the number of particles of the system
F_a = the force on the a-th particle
r_a = the position of the a-th particle
where the right hand side was named by Clausius "virial". Notice also the factor -1/2 on the right hand side (RHS). If the forces on each particle are derivable from some potential U_a, then (1) transforms to the following form:
<T> = (1/2) <Σ r_a * grad(U_a)> (2), since in this case F_a = - grad(U_a).
Of particular interest is the case of 2 particles that interact via some central force-> F analogous to (r^n) , where n = some exponent.
In this case the potential energy of interaction takes the form U = k*r^(n+1), where k = proportionality constant. Thus, for this particular case it is (r = relative position of the 2 particles, U = potential energy of interaction), in spherical coordinates (see the RHS side of (2)):
r*grad(U) = r*dU/dr = k(n+1)*r^(n+1) = (n+1)*U (3), since U = k*r^(n+1).
Combining (3) and (2) (for the case of 2 particles always) we find that
<T> = (n+1)/2 * <U> (4).
If the mutual interaction is gravitational then n = -2 (see the force dependence on r above, how it was defined) and from (4) it comes out that
<T> = -(1/2) * <U> .
This is a useful relation for calculations concerning the planetary motion.
In the alternative answer of GR0177 #3, the argumentation is correct but the virial theorem does not seem to be employed correctly. In general, think carefully before reading the solutions given on this site. I have met several errors in the quoted answers. Think before you "digest" the quoted answer.