Hafiz Mohammad Saeed, the former leader and founder of Lashkar-e-Taiba, was put under house arrest in Lahore in August, shortly before he was due to address a rally.
After being released briefly on August 28, he was re-arrested under a law allowing authorities to detain anyone without trial for up to three months.
"The court has declared that the detention of Hafiz Saeed is against the law and the constitution and he should be released immediately," his lawyer, Nazir Ahmed Ghazi, said on Tuesday.
Saeed was still being held under house arrest in Lahore but one of his aides said it was hoped he would be released later in the day.
Saeed founded Lashkar-e-Taiba in the early 1990s but quit as leader days after India accused it of involvement in an attack on the Indian parliament in December 2001, which brought Pakistan and India to the brink of a war.
Indian police also accused Lashkar and Pakistan's military spy agency, Inter-Services Intelligence, of involvement in the bomb attacks on commuter trains in Mumbai on July 11.
Both Pakistan and Lashkar have refuted the allegation.
Pakistan banned Lashkar-e-Taiba in January 2002.
'Victory for truth'
Saeed became the head of a charity, Jamaat-ud-Dawa, which the US calls a terrorist organisation because of its ties to Lashkar.
Pakistan has put the charity on a watchlist of terrorist organisations but not banned it.
A spokesman for Jamaat-ud-Dawa hailed the court decision as "victory for the truth".
"Hafiz Saeed was detained under pressure from India," Abdullah Montazir said.
"The government should give us an opportunity to respond to the Indian charges instead of taking action against us."