According to traditional Muslim history: it was built by Umar the second caliph, then rebuilt and expanded by the Umayyad caliph Abd al-Malik and finished by his son al-Walid in 705 CE. It was originally a garbage dump, meaning such a building did not exist when 17:1 was revealed.