Built during renovations of Jerusalem in the 1st century BCE, the ancient wall that constitutes Judaism’s holiest site was not part of the Temple itself, but of a structure surrounding the Temple Mount. Nadav Shragai explores its history as a place where Jews gather to pray, beginning with the massive earthquake that struck Jerusalem in 1546:
The severe quake tore down a row of old structures built and propped up by the Western Wall. . . . The clearing of the ruins slightly expanded the limited area of about 488 meters where Jews had prayed since approximately the year 1000. Suddenly, after years of covering many parts of the Western Wall with Muslim construction—mostly Mamluk [i.e., dating to the 13th century]—a narrow and empty plaza was created at the foot of the wall, the closest of the Temple Mount walls to the presumed site of the Holy of Holies. The Jews hurried to make use of this area for their prayers. This area later became known as the “alley of the Western Wall,” and after the Six-Day War turned into the “Western Wall Plaza,” which Israel prepared as a large open area for Jewish prayers in 1967.
Although, as Shragai notes, there is scant evidence of prayer in front of the wall before the second millennium, earlier sources attest to the site’s special sanctity:
The proximity of the Western Wall to the presumed place of the Holy of Holies has for many generations given tangible expression to the concept of a “Divine Presence [sh’khinah] in the west,” which appears in many Jewish sources. . . . For example, Midrash Tanḥuma, [a rabbinic compilation dating to somewhere between the 6th and 8th centuries CE, states]: “The Divine Presence never moved from the Western Wall of the Temple.”
There is a dispute among the commentators as to which Western Wall these midrashim and other sources, which were written about 1,500 years ago, referred to. To the western wall of the Temple? Or to the western (retaining) wall of the Temple Mount? But there is no dispute that after the destruction of the Second Temple, . . . when the site of the western wall of the Temple itself disappeared, the Jewish people consecrated the retaining wall of the Temple Mount compound. Contrary to [what some today would claim], the Jewish people have had an intimate connection to the Western Wall and held prayers [there] for many centuries before the earthquake.
Read more on Jerusalem Center for Public Affairs: https://jcpa.org/article/the-western-wall-and-the-jews-more-than-a-thousand-years-of-prayer/