Short answer: Context. The reason of the different in construction time is context. Hagia Sophia was built by a powerful, very developed centralized and burocratized Estate following the very strong will of its ruler at the time, whom needed to symbolically consolidate his position AFAP; on the other hand, medieval cathedrals were locally financed projects developed by small communities that had in no way access to the material, human and organizational power as the Roman State under Justinian.
Hagia Sophia was intended to be an expression of power from its very conception. The immediate political context in which it was built is well known: the second Hagia Sophia had just recently burned during a massive popular revolt that had almost toppled the regime, known as the Nika Revolts. Justinian was actually one of the very few emperors of the romans to (politically) survive a massive popular uprising, and it meant using the army to massacre tens of thousands of citizens. The Hagia Sophia was built literally on the smoking ashes of a massive act of what romans could only call tyranny. Furthermore, although roman republican tradition of public building construction as a way for the elites to gain popular favor had almost vanished by Justinian’s time, churches and monasteries were somehow an exception to that rule, and during the first years of his reign he had to deal with a “problematic” project: the Church on Saint Polyeuctus. By far the most magnificent and lavish church of the city, it had been recently commissioned by Anicia Juliana, a very rich woman from imperial descent and a political rival to Justinian. Surpassing this magnificent new church with an even greater new one would show his control over the state and assert his legitimacy as Emperor of the Romans. These were the two main personal impulses for Justinian to commission such a massive building to be erected in a short period of time.
The less immediate context was favorable, too, for the Roman State to be successful in building the Hagia Sophia in such a short amount of time; not only the knowhow accumulated for centuries was readily available, but massive funds, too: Justinian enjoyed the benefits of Teodosius I economic reforms and savings policy.
So these three factors united into Justian being able to get such a massive building erected in (only less than) 7 years:
Technical knowledge and an experienced workforce, not to mention a strong tradition of massive public and private building construction not only in Constantinople but throughout the whole roman polity; there was nothing “new” about a huge massive public building being constructed in Constantinople, nothing out of the ordinary was needed, except for maybe bigger numbers, as the project was specially huge, but not exceptionally so. Compare that to how exceptional the building, if not the mere existance, of a massive cathedral meant for small urban communities it Europe.
A State machine strong enough to overtake the financial, human and organizational effort, and a political situation “calm enough” to favor the massive expending needed. The treasury was full, the people angry and Justinian’s name stained: a massive program of public spending and job creation was not an unprecedented move by a roman strongman being accused of tyranny.
The strong will of Justinian, who really wanted the building to happen, and to happen quickly; the revolt and mass murdering process had left the city in ashes and he wanted the rebuilding to leave his personal mark on the capital; in front of the church he had a column built, topped by and equestrian statue of his, that reached as high as Hagia Sophia’s dome. Some of the weird design aspects of the Hagia Sophia as a building (the ugly double colonnade in the upper galleries for example, the lack of figurative decoration) have been read by historians as signs of rushing the construction process. Furthermore, the center of the capital sure needed to be rebuilt fast for practical reasons. Oh and by the way, this justinianic policy of massive public works was not limited to the Hagia Sophia; it spanned from defensive fortifications in the Balkans to the reconstruction of the entire city of Antioch (the Persians had razed the city, copied it building by building in their hinterland, named it “krusro’s better Antioch” and moved the whole population there), not to mention a considerable number of other religious buildings and restorations.
Compare that, then, to the context of building a huge gothic cathedral in medieval Central Europe. As little as I know about local economies and politics in Central Europe in the Late Middle Ages, the power of whatever organization ordered the new building was extremely small compared to that of Justinian. Economic resources were thus limited; even if there hadn’t been, manpower was limited, material resources were limited, even technical know-how and organizational experience were limited; you needed to quarry all those mampostery blocks, compared to the proto-industrial brick production of romans Late Antiquity. There would have been a total lack of communicational infrastructures between resource centers in the middle ages compared to roman times, so forget about bringing tons of colored marble from all over the mediterranean world: resources were limited to what was available locally, or maybe regionally.
So, in short, the Hagia Sophia and a random medieval Gothic Cathedral may have a lot in common as material realities (both are monumental religious-focused buildings on a massive scale), but the social, political and economic circumstances in which they were conceived differ so greatly that they are very hard to compare in practical terms.