This church was the MAIN church of Orthodox Christianity and where the Patriarch of Constantinople sat. Sultan Mehmet II, who dealt the final blow to the Byzantines, felt it simply would be fitting and symbolic to change the main church of Orthodox Christianity into mosque. Plus, it was a beautiful building, so most Muslims agreed with Mehmet on changing it into a mosque. It also helped solidify Mehmet's claim of being the 'heir to Rome' which he along with Russia claimed after destroying Byzantium.
Tl;dr, symbolism, pretty building, insult, and claim to Roman Empire
You should also note that this isn't uncommon! Lots and lots of buildings have been repurposed between religions in the past. For example, during the era of the Crusades, many churches and mosques were rededicated and converted as one side defeated another. In Jerusalem itself this happened when a new conqueror occupied the city and wanted their religion represented instead!