Since, in the course of the Night Journey, the Prophet not only journeys to heaven, meets Old Testament prophets and Jesus, and speaks with God face-to-face, but does so on the back of a winged horse; I think it's churlish, not to mention dull-headed, to question the incident in which he merely worships in a masjid which did not happen to exist at the time!
Much that is omitted in the Qur'an is supplied (a bit too readily, however) in the Hadith. For those who have submitted to God in their hearts, that the Qur'an may be the inspired word of God and the attested work of the Prophet; whereas the Hadith is merely a body of things the Prophet is reputed in legend to have said, makes no difference to the brilliance of their faith.
For the rest of us, the Qur'an, for all its gnomic and poetic occlusions, must be taken as the sole authority on the matter. And in that light, you must realise that it is a book of prophecy, a text in which the timeline is encyclopaedic, and the POV eternal: accordingly, our ideas of past and future do not apply. The Prophet was able to pray at a mosque in Jerusalem out of the mystic's certainty that there would be such a mosque in time to come. Indeed, and in a blink of the Divine eye, there was such a mosque.
Nam Sibyllam quidem Cumis ego ipse oculis meis vidi in ampulla pendere, et cum illi pueri dicerent: Sibylla ti theleis; respondebat illa: apothanein thelo.