The Council of State heard the case for half an hour after President Recep Tayyip Erdoğan referred the issue to the court.
“If they rule so, we will turn it into a mosque,” Erdoğan previously said.
The government decision to turn the mosque into a museum was made in 1934 in the early years of the Turkish Republic founded by Mustafa Kemal Atatürk.
U.S. Secretary of State Mike Pompeo on July 1 urged Turkey to let Hagia Sophia remain a museum, while the spiritual head of the world’s Orthodox Christians warned its conversion to a mosque would sow division.
Hagia Sophia was the foremost church in Christendom for 900 years and then one of Islam’s greatest mosques for 500 years after the Ottoman conquest of Istanbul.
Turkish groups have campaigned for years for Hagia Sophia’s conversion into a mosque and Erdoğan backed their call ahead of local elections last year.