The judge ruled that Daniel Galvan Vina, a Spanish national found guilty of raping 11 children aged between four and 15 in Morocco and sentenced to 30 years in prison there, was a flight risk and would remain in custody while his extradition was being considered, the court said.
Galvan, 63, was arrested Monday at a hotel in the southeastern Spanish city of Murcia where he once worked at a university after Morocco issued an international arrest warrant against him.
Morocco is seeking the extradition of Galvan, who was among 48 Spanish prisoners pardoned by King Mohamed VI and freed last week from jail following a visit in mid-July to Morocco by Spain's King Juan Carlos.
The pardon was revoked by the king on Sunday, two days after baton-wielding police dispersed several thousand people who tried to rally in front of the parliament in the Moroccan capital Rabat.
A royal palace statement said the king had been unaware of the nature of Galvan's crimes and on Monday the Moroccan monarch dismissed the director of prisons after an enquiry blamed his department for Galvan's release under royal pardon.
King Mohamed invited the families of the victims to his Rabat palace on Tuesday to offer them "moral support and help them recover from the wounds caused by Galvan's atrocities and governmental mistakes".
Galvan's name appeared on a list of 30 Spanish prisoners in Morocco whom Madrid had asked to be sent home to serve out their sentences, a source close to the dossier told AFP.
The Spanish embassy in Morocco also sent a separate list of 18 people it wanted pardoned, the source added.
King Mohamed pardoned all 48 Spanish prisoners including Galvan on Throne Day on July 30, an annual holiday celebrating Morocco's ruling family and often a day of royal pardons.
The Moroccan justice ministry said Galvan and the 47 other Spanish prisoners received the royal pardon in response to a request from Spain's king.
But Spain's royal household said Juan Carlos had not asked for the release of Galvan or any other Spanish prisoner during his visit and had only shown interest in the wellbeing of Spanish nationals held in prisons in the north African country.
Spain and Morocco do not allow their citizens to be extradited to each other's country and an exception would have to be made if he is sent back to the north African nation.
The case is also complicated by the fact that in Spain the government can not revoke a pardon.
Galvan was born in Iraq but acquired Spanish citizenship after he married a Spanish woman who he has since divorced, the court said.
He has lived in several countries including Egypt, Syria, Jordan, Britain and Morocco, it added.
The affair has caused embarrassment in both Morocco and Spain, with questions being raised about Galvan's background.
Daily newspaper El Pais reported that Galvan told his Moroccan lawyer that he was a former official in the Iraqi army who had worked with foreign secret services to oust Saddam Hussein.
The name Daniel Galvan was "an identity that was fabricated by secret services when they got him out of Iraq, they provided him with Spanish documentation and converted him into a retired professor from Murcia," the newspaper said.
Galvan worked at the University of Murcia until 2002, before moving to the Moroccan port of Kenitra in 2005. He told his neighbours there that he was a retired professor, daily Spanish newspaper El Mundo reported.
Galvan lacked "family, social, economic or work links that would neutralise the temptation to put himself beyond the reach of the justice system if he was set free," Spain's top criminal court, the National Audience, wrote in its ruling.