I found the following excerpt on this web site: http://jeff560.tripod.com/d.html. It gives references to specific papers of both Lagrange and Gauss. The inverse square law for the electric force is usually associated with Coulomb, but was apparently first inferred by Priestley on the basis of Franklin's observation that there is no electric field inside a hollow conductor and analogy to the known analogous property for gravity.

The history of the theorem is bewildering with many re-discoveries.

O. D. Kellogg Foundations of Potential Theory (1929, p. 38) has the following note on the result “known as the Divergence Theorem, or as Gauss’ Theorem or Green’s Theorem”:

A similar reduction of triple integrals to double integrals was employed by Lagrange: Nouvelles recherches sur la nature et la propagation du son Miscellanea Taurinensis, t. II, 1760-61; Oeuvres t. I, p. 263. The double integrals are given in more definite form by Gauss Theoria attractionis corporum sphaeroidicorum ellipticorum homogeneorum methodo novo tractate, Commentationes societas scientiarum Gottingensis recentiores, Vol III, 1813, Werke Bd. V pp. 5-7. A systematic use of integral identities equivalent to the divergence theorem was made by George Green in his Essay on the Mathematical Theory of Electricity and Magnetism; Nottingham, 1828 [Green Papers, pp. 1-115].
Kline (pp. 789-90) writes that Mikhail Ostrogradski obtained the theorem when solving the partial differential equation of heat. He published the result in 1831 in Mem. Ac. Sci. St. Peters., 6, (1831) p. 39. J. C. Maxwell had made the same attribution in the 2nd edition of the Treatise on Electricity and Magnetism (1881). See also the Encyclopaedia of Mathematics entry Ostrogradski formula

For Gauss’s theorem Hermann Rothe “Systeme Geometrischen Analyse, Erster Teil” Encyklopädie der mathematischen Wissenschaften mit Einschluss ihrer Anwendungen Volume: 3, T.1, H.2 p. 1345 refers to Gauss’s Allgemeine Lehrsätze in Beziehung auf die im verkehrten Verhältnisse des Quadrats der Entfernung wirkenden Anziehungs- und Abstossung-Kräfte 1839 in Werke Bd. V (especially pp. 226-8.)