The project to build a railroad in the Yucatán Peninsula is President Andrés Manuel López Obrador's flagship infrastructure programme.
But cavers warn that it threatens caverns dating back millions of years.
The judge ordered works to be halted until studies could be carried out about the works' environmental impact.
Cavers had joined forces with environmentalists to bring the case to court last month.
They argued that a change in the route of the train line linking the tourist hotspots of Cancún and Tulum, known as Section 5, would harm the jungle it will now run through and the network of caves which lies beneath it.
Judge Adrián Novelo said building work on this 120km (75 mile)-stretch should be suspended because "a continuation of the works (...) implies the cutting down of trees, the destruction of flora and native species, and the perforation of the ground".
Environmentalists and speleologists had warned that construction work would damage the cave system which has been created over millions of years.
Aleira Lara, director of campaigns for Greenpeace Mexico, told the BBC that she welcomed the judge's decision and hoped it would result in a permanent suspension of construction work.
Ms Lara also praised the efforts of the cavers and their lawyers in getting their case heard in court.
She said that following the rerouting of Section 5, the obligatory environmental impact studies had not been carried out, meaning that the new route was in breach of environmental laws.
Ms Lara says that the caves are not only havens of biodiversity and home to animals such as bats and blind cavefish, but also act as places of refuge for jaguars who use them as a source of drinking water.
"The construction work is altering the ecosystem and that has a serious impact on biodiversity."
Judge Novelo agreed that a continuation of the works would entail "a high probability of a change in the ecosystem".
A decision on whether the suspension will be made permanent is scheduled to be taken on Friday.
The $9.8bn (£7.5bn) Maya train project is aimed at building a 1,500km-long railroad linking the south-eastern Mexican states of Chiapas, Tabasco, Campeche, Yucatán and Quintana Roo.
It has been controversial from the start. President López Obrador has argued that it will provide an environmentally friendly mode of transport for locals and tourists alike, as well as boosting development and employment in the underdeveloped region.
But critics say the megaproject has been rushed and environmental concerns have been overridden.
The president has dismissed warnings by activists labelling them as "pseudo-environmentalists" and questioning their motives for opposing the project.
Despite delays and protests, the president is adamant the project will be inaugurated in December 2023.