A lawyer for the detainees said they would be released in 48 hours on bail following an order by the Ofer military court on Tuesday.
Three Palestinian cabinet ministers, one of them a parliament member, and 18 other members of parliament would be freed, he said.
The Israeli army had no immediate comment on the terms of the release or why it was ordered, but said the release would be deferred until Thursday so prosecutors had an opportunity to appeal.
An army spokesman said: "Twenty-one Hamas officials are to be released, but this has been put on hold for 48 hours so the prosecution can file challenges."
He also said that a successful appeal would put the release on hold.
Israeli forces took at least 30 Hamas officials into custody after an Israeli soldier, Corporal Gilad Shalit, was seized in a raid on June 25.
Israel said the detainees were suspected of offences linked to Hamas's role in spearheading a six-year-old Palestinian uprising against the occupation. But Palestinians accused Israel of rounding up "bargaining chips" to force Shalit's release.
A senior aide to Ismail Haniya, a Hamas leader and the Palestinian prime minister, said the court's decision represented "significant progress" in securing Shalit's release.
Ahmed Youssef told Israel Radio: "The military court decision is part of a deal coming together to release Shalit, and in the coming days more will be known."
A lawyer representing the detainees, Osama al-Saadi, said the release was conditional on posting a collective bail of 25,000 shekels ($5,690).