I can't tell you how this formula was derived, but it is mentioned in the book: "Fractals, Chaos, Power Laws, Minutes from an infinite paradise" by Manfred Schroeder, ISBN 0-7167-2136-8. Also mentioned here is a different formula from Ramanujan which is based on a recursive algorithm from transformation theory for elliptic integrals. This work is written in the paper: "Modular equations and approximations to pi" Quar. J. Math. 45, 350-372. This is not much information, but it might be a start.