The handcuffed defendants, many of them crying, arrived in court with their heads bowed as police pushed them inside a metal cage, an AFP correspondent reported.
"I am innocent. I was in the hammam for therapy, I swear in the name of Allah," said a defendant as he wept inside the cage, indicating that he was in the steam room of the bathhouse to treat back pain.
"The police beat us every day and force us to sleep on our stomachs," said another.
Egyptian law does not expressly ban homosexuality, but gay men have previously been arrested and charged with debauchery instead.
The defendants were arrested on December 7 in a night raid on a hammam in central Cairo's Azbakeya district.
An Egyptian television presenter who filmed the raid as the near naked men were loaded aboard police trucks aired the footage days later.
The bathhouse owner and four employees are also on trial. Most of the defendants appeared to be between 40 and 50 years old, an AFP correspondent said.
Relatives of the defendants were banned from attending Sunday's hearing.
Angry relatives stopped photographers from taking pictures outside the court, while some mothers cried and screamed.
"Don't defame our sons, they are real men," shouted one mother.
A brother of one defendant insisted to AFP that he was innocent.
"This is about our honour. This will destroy our entire family," he said, accusing television presenter Mona Iraqi of "fabricating the case".
Signup to our newsletter and follow us on Facebook and Twitter!
"It's all because of a journalist who seeks fame," he alleged.
Iraqi is said to have reported the hammam to police after researching a programme on AIDS and prostitution.
She said on her Facebook page that airing the footage was not aimed at targeting homosexuality, but was part of a "series uncovering male sex trafficking and the spread of AIDS in Egypt".
The court adjourned the trial to January 4.
Twenty-one defendants underwent "forensic tests" to determine whether they were homosexuals, forensic department spokesman Hisham Abdel Hamid told AFP.
"Three of them have fresh marks of non-consensual sexual assault," Abdel Hamid said.
"Eighteen others have no visible marks to show that they are homosexuals, but that does not mean that they are not homosexuals."
Such medical tests have long been used in Egypt to identify suspected homosexuals.
The bathhouse raid is the latest in a police crackdown on gays, and came two months after a court sentenced eight men to three years over a video prosecutors said was of a gay wedding.
"This bathhouse has been operating for a hundred years," defence lawyer Mohamed Zakaria Al-Tobgy said.
"The defendants were filmed on camera with their towels on, which is how one is inside a bathhouse."
Advocacy groups such as New York-based Human Rights Watch have condemned both the prosecution of homosexuals in Egypt and the tests carried out on them.
In the past homosexuals have been jailed on charges ranging from "scorning religion" to "sexual practices contrary to Islam".