How did Ramanujan find this formula?
Solution 1:
The question about "how Ramanujan get this formula" is, in general, very mysterious. Nobody knows how he came up with his thousands of formulas. He was a genius of the highest order and we can only speculate how he was able to do what he did. He was familiar with many special examples and formulas and was able to do elaborate symbolic and numerical calculations combined with extraordinary intuition. Hardy worked closely with Ramanujan in his last years and wrote Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work and gives his opinions on Ramanujan's methods.
From the theory of Fibonacci/Lucas sequences the ordinary generating function of such a sequence is the reciprocal of a quadratic. For example: $$ \sum_{n=0}^\infty F_{n+1} T^n = 1/(1-T-T^2).$$ Ramanujan may have asked "What is the o.g.f. of a product of two such sequences?". The left side of equation $(1)$ is the o.g.f. and the right side is the rational function answer to that question. Expanding the coefficient of $\,T^n\,$ on the left side and splitting the infinite sum into four infinite sums of geometric series we get the left side of equation $(2)$. The happy surprising result is how simple the numerator of the right side is.
Just to be clear, the key step is to expand the product $$ (a^{n+1}\!-\!b^{n+1}) (c^{n+1}\!-\!d^{n+1}) \!=\! (ac)^{n+1} \!-\! (ad)^{n+1} \!-\! (bc)^{n+1} \!+\! (bd)^{n+1}. $$
EDIT: The Wikipedia article generating function transformation section on Hadamard product of rational generating functions has an example which is essentially the Ramanujan formula -- just not expressed in terms of the roots of the quadratics, but rather the coefficients of the quadratics.