Newton's law of universal gravitation:
"Newton's law of universal gravitation states that every point mass in the universe attracts every other point mass with a force that is directly proportional to the product of their masses and inversely proportional to the square of the distance between them."
Coulomb's law:
"The magnitude of the Electrostatics force of interaction between two point charges is directly proportional to the scalar multiplication of the magnitudes of charges and inversely proportional to the square of the distances between them."
How did Sir Isaac Newton and Sir Charles Augustine De Coulomb come to know that the force, gravitational or coulomb's, is inversely proportional to the square of the distance between two point masses or charges, why didn't they just say that the force is inversely proportional to the distance of two bodies from each other or two charges? There must have been something that made them formulate these inverse-square laws.
Best Answer
The short answer is "observations".
In the case of the gravitational law, the orbits of the planets around the sun, the moon around the earth fit mathematically a force with an inverse square law for the distance. An inverse law does not.
In the case of electricity this article points out the observational history:
and then others took it from there to end up with the comprehensive publications of Coulomb, based on measurements.