Spatial and symmetry constraints as the basis of the virial theorem and astrophysical implications