Could someone tell me how Sir Issacc Newton derived the equation for the Universal law of gravitation?

From Kepler's law, Newton knew that for circular orbits of radius $r$, $T^2\propto r^3$. However, since Newton also knew calculus and kinematics, he knew that the centripetal acceleration of an object in uniform circular motion is $a_c=rw^2$. Or, in terms of the time period, $a_c=\frac{4\pi^2 r}{T^2}$. Combining this with the Kepler law, Newton could deduce that $a_c\propto\frac{r}{r^3}$, or, $a_c\propto\frac{1}{r^2}$.

Moreover, Newton also knew his second law. So, he deduced that if a celestial object is in a circular orbit then since it is performing a motion that has non-zero acceleration, there must be a force acting on it. Since the acceleration of such a celestial object was simply the centripetal acceleration $a_c$, the force on it must be $ma_c$ towards the center. Let's call this force $F_g$ then $F_g=ma_c\propto\frac{m}{r^2}$. But clearly, if, say the Earth (mass $M$) is applying this force on the Moon (mass $m$) then the Moon should also be applying the same force (in the opposite direction) on the Earth according to the third law of Newton. This can only be generically true if $F_g$ is also proportional to $M$. Thus, $F_g\propto\frac{Mm}{r^2}$.

Newton's genius was also in realizing that this force is not limited to describing the dynamics of celestial bodies but also applies to the dynamics of objects falling to the Earth on ground. He could verify this by confirming that the acceleration of freely falling objects near the ground was in agreement with the prediction from his universal law of gravitation.

Newton knew Kepler's Laws, which state that:

  1. The planets of the Solar System orbit in ellipses with the Sun at one focus.
  2. A radius drawn from the Sun to an orbiting body sweeps out equal areas in equal times.
  3. The orbital period of a body is proportional to the $3/2^\text{th}$ power of the length of the major axis of the ellipse around which it moves.

In fact, only the first law is needed to derive the form of the force of gravity, as I will now show.

If we work in 2D polar coordinates aligned with the orbital plane of the planet with the Sun at the origin, then the equation of the path of a planet is $$ r = \frac{p}{1 +e\cos\phi}\tag{1} $$ (see wikipedia for a derivation). In this coordinate system, $$ \mathbf{e}_r = \left(\begin{matrix} \cos\phi\\ \sin\phi \end{matrix}\right) \quad\text{and}\quad \mathbf{e}_\phi = \left( \begin{matrix} -\sin\phi\\ \cos\phi \end{matrix} \right) $$ are the basis vectors. The angle $\phi$ is a function of time, so the basis vectors are also. Differentiating them gives that $$ \dot{\mathbf{e}}_r = \left( \begin{array}{cc} -\dot{\phi}\sin\phi\\ \dot{\phi}\cos\phi \end{array} \right) = \dot{\phi}\mathbf{e}_\phi, \quad \dot{\mathbf{e}}_\phi = \left( \begin{array}{cc} -\dot{\phi}\cos\phi\\ -\dot{\phi}\sin\phi \end{array} \right) = -\dot{\phi}\mathbf{e}_r. $$ The position vector of a particle is $\mathbf{r} = r\mathbf{e}_r$, so its velocity and acceleration are \begin{align} \dot{\mathbf{r}}&= \dot{r}\mathbf{e}_r + r\dot{\mathbf{e}}_r = \dot{r}\mathbf{e}_r+r\dot{\phi}\mathbf{e}_\phi \\ \ddot{\mathbf{r}} &= \ddot{r}\mathbf{e}_r + \dot{r}\dot{\mathbf{e}}_\phi + \dot{r}\dot{\phi}\mathbf{e}_\phi +r\ddot{\phi}\mathbf{e}_\phi + r\dot{\phi}\dot{\mathbf{e}}_\phi = (\ddot{r}-r\dot{\phi}^2)\mathbf{e}_r + (2\dot{r}\dot{\phi}+r\ddot{\phi})\mathbf{e}_\phi \end{align}

It is sensible to assume that the force between the two bodies acts along the line connecting them, since this is the only unique direction defined in space. It must also depend only on the distance between them, as space is invariant with respect to rotations about this line so the force cannot depend on the angle. That is to say, $\mathbf{f} = f(r)\mathbf{e}_r$.

In this case the angular momentum $\mathbf{J} =\mathbf{x}\times \mathbf{p}$ of the particle in orbit must be conserved, as $$ \frac{d}{dt}\mathbf{J} =\underbrace{\dot{\mathbf{x}}\times \mathbf{p}}_{\mathbf{v}\times m\mathbf{v} = \mathbf{0}}+\underbrace{\mathbf{x}\times\dot{\mathbf{p}}}_{r\mathbf{e}_r\times f(r)\mathbf{e}_r = \mathbf{0}}=\mathbf{0} $$ The magnitude of angular momentum is $J = r \cdot mv = mr^2\dot{\phi}$, so $$ \dot{\phi} = \frac{J}{mr^2}, \quad \ddot{\phi} = -\frac{2J}{mr^3}\dot{r} $$ Finally, to find $\ddot{\mathbf{r}}$ it is necessary to compute $\dot{r}$ and $\ddot{r}$ by differentiating equation (1): \begin{align} \dot{r} &= -\frac{p}{(1+e\cos\phi)^2}\cdot(-e\sin\phi)\dot{\phi} = \frac{r^2}{p}\cdot e\sin\phi\cdot\frac{J}{mr^2} = \frac{Je}{mp}\sin\phi \\ \ddot{r} &=\frac{Je}{mp}\dot{\phi}\cos\phi =\frac{J}{mp}\cdot\frac{J}{mr^2}\cdot\left(\frac{p}{r}-1\right) = \frac{J^2}{m^2}\frac{1}{r^3} - \frac{J^2}{m^2p}\frac{1}{r^2} \end{align} Plugging this in gives \begin{align} m\ddot{\mathbf{r}} &= m\left[\left(\frac{J^2}{m^2}\frac{1}{r^3} - \frac{J^2}{m^2p}\frac{1}{r^2} - r\cdot\left(\frac{J}{mr^2}\right)^2\right)\mathbf{e}_r + \left(2\dot{r}\cdot\frac{J}{mr^2}+r\cdot\left(-\frac{2J}{mr^3}\dot{r}\right)\right)\mathbf{e}_\phi\right]\\ &= -\frac{J^2}{m^2p}\cdot\frac{m}{r^2}\mathbf{e}_r = -\frac{(r_0v_0)^2}{p}\cdot\frac{m}{r^2}\mathbf{e}_r =\mathbf{f}(r) \end{align} Thus $$ f(r) = -\frac{\alpha m}{r^2} $$ is the only possible functional form of $f$. The same force acts on the Sun, so by symmetry if it is proportional to the mass of the planet, it must also be proportional to the mass of the Sun, that is $\alpha = G M$ for some constant $G$: $$ \mathbf{f} = -\frac{GMm}{r^2}\mathbf{e}_r $$ Kepler's second and third laws follow from here! I don't know if this is how Newton actually derived it - I seem to remember that he just wrote down the law in Principia without any derivation - but it is certainly plausible that he used a method similar to this one.

Newton's law of gravity cannot be derived in the bounds of Newtonian mechanics. As for the inverse square law it can be understood as geometric dilution corresponding to point-source radiation into three-dimensional space (see diagram) enter image description here.This article might help you.