The formula is derived in Willans, On Formulae for the nth Prime Number (1964) (Mathematical Gazette
vol. 48, no. 366, pp. 413-415), who references Dickson's History of the Theory of Numbers, ch. XVIII "for references to other formulae of this nature". He does not quite mean explicit formulas for $p_n$, but rather explicit formulas for functions that take different types of values on primes and non-primes (and can be adapted to the task by simple manipulations that Willans sketches). Explicit formulas of a somewhat different nature were published earlier by Mills A prime-representing function (1947) and Wright A Prime-Representing Function (1951).
Dickson gives a couple of examples, including Pocklington's 1911 example based on Wilson's theorem that seems to be Willans's inspiration. Later variations on the theme are reviewed in Dudley's Formulas for Primes (1982), who remarks:"Although Wilson's Theorem has proved to be notoriously unuseful in finding primes, this has not stopped the production of formulas in which it is essential". Interestingly, Willans shared the sentiment, and already felt the need to justify the exercise:
"While the formulae in this article are unsuitable for application to problems in prime number theory, they at least provide definite answers to the questions (see e.g. Hardy and Wright, An Introduction to the Theory of Numbers, § 1.5):
Is there a formula for the nth prime number?
Is there a formula for a prime, given the preceding prime?"
Connes, the Fields medalist best known for developing noncommutative differential geometry, wrote a recent follow-up Around Wilson's theorem (2018) that quotes Willans's related formula for the prime number function. Rowland's A natural prime-generating recurrence (2017) quotes Willans's formula from the OP noting that it and its relatives are "generally infeasible to compute in practice".