The following excerpt is from Space—Time—Matter by Hermann Weyl, starting on page 101. Among the things I'm not understanding is Weyl's assertion that the integral of $\nabla\cdot(\phi\mathbf{E})$ vanishes due to Gauss's theorem. Why should I believe that?
The potential $\phi$ is defined by $\mathbf{E}=\nabla\phi.$ I've noticed the current German language edition has some of the signs reversed, so that might correctly be $-\phi.$ But I don't think that matters for my question.
A system of discrete point-charges $e_{1}, e_{2}, e_{3},\dots,$ has potential energy $$ U = \frac{1}{8\pi} \sum_{i \neq k} \frac{e_{i} e_{k}}{r_{ik}} $$ in which $r_{ik}$ denotes the distance between the two charges $e_{i}$ and $e_{k}$. This signifies that the virtual work which is performed by the forces acting at the separate points (owing to the charges at the remaining points) for an infinitesimal displacement of the points is a total differential, viz. $\delta U$. For continuously distributed charges this formula resolves into $$ U = \iint \frac{\rho(P) \rho(P')}{8\pi r_{PP'}}\, dV\, dV' $$ in which both volume integrations with respect to $P$ and $P'$ are to be taken over the whole space, and $r_{PP'}$ denotes the distance between these two points. Using the potential $\phi$ we may write $$ U = -\tfrac{1}{2} \int \rho\phi\, dV. $$ The integrand is $\phi \nabla\cdot\mathbf{E}$. In consequence of the equation $$ \nabla\cdot(\phi\mathbf{E}) = \phi \nabla\cdot\mathbf{E} + \mathbf{E}\cdot \nabla\phi $$ and of Gauss's theorem, according to which the integral of $\nabla\cdot(\phi\mathbf{E})$ taken over the whole space is equal to $0$, we have $$ -\int \rho\phi\, dV = \int (\mathbf{E} \cdot\nabla\phi)\, dV = \int |E|^{2}\, dV; $$ i.e. $$ U = \int \frac{1}{2} \left|\mathbf{E}\right|^{2} dV . $$