The website Snopes documents and posits various reasons behind the number being featured, but finds no conclusive evidence.
Here are the unsupported theories put forward, to save everyone a click:
A blog created by Kubrick’s fans hypothesized that Kubrick repeatedly referenced the number 42 (as well as 24, 21, and 12) after studying Sigmund Freud‘s writings outlining the “unsettling effect that recurring numbers can have.”
It is possible, as well, the original BBC Radio 4 broadcast of Douglas Adams’ “Hitchhikers Guide to the Galaxy” — which aired via multiple episodes in 1978 — influenced Kubrick. According to The Frida Cinema, an Orange County art house nonprofit, scenes from “The Shining” were shot in London that same year.
Meanwhile, Geoffrey Cocks, a retired history professor, has a more specific theory. Cocks — a source in the 2012 documentary “Room 237” that dissects the film’s possible hidden messages and author of the book titled, “The Wolf at the Door: Stanley Kubrick, History, and the Holocaust” — believes the “42” reference helps paint an allegory about Nazi extermination.
“1942 was the year of the Final Solution, and 42 has been used as shorthand to refer to the Holocaust,” Vulture published in 2013, citing Cocks’ theory.
Is there an explanation attributable to Stanley Kubrick as to why he referenced the number 42 so often in the movie?
42
referenced there?apple pie
. And Lewis Carroll used42
so it's not the first popular work to use it; it's not chosen randomly.