Proof of Thomson's theorem of electrostatics