The rights group Human Rights Watch claimed that seven women were subjected to the tests.
The ban came a week after public outrage over scenes of soldiers dragging women protesters by the hair, stomping on them and stripping one half-naked in the street during a fierce crackdown on activists, Fox News reports.
According to the report, a three-judge panel said in its ruling that the virginity tests were "a violation of women's rights and an aggression against their dignity."
The ruling also said a member of the ruling military council admitted to Amnesty International in June that the practice was carried out on female detainees in March to protect the army against possible allegations of rape, indicating it was an administrative order and not an individual decision.
"Because the military is also acting as a police force, it is the duty of the armed forces when carrying out these duties to abide by the law and not violate its provisions when dealing with citizens," the court ruling said.
A 25-year-old woman Samira Ibrahim was the first one to complain publicly about the degrading practice. She filed two suits against the practice, one demanding it be banned and another accusing an officer of sexual assault.