Legislator Leung Kwok-hung should not have had his "iconic" long hair shorn off by prison authorities, a court ruled yesterday.

High Court Justice Thomas Au Hing- cheung said the Correctional Services Department's standing order requiring all male prisoners to have their hair cut "sufficiently close but not close-clipped" violated the Basic Law and sex discrimination law.

Leung, nicknamed "Long Hair," had his hair cut when he was jailed for four weeks at the Lai Chi Kok Reception Centre in June 2014 after being convicted in 2012 of disturbing a forum on the Legislative Council.

Leung's long hair was cut by an inmate barber under the supervision of a day orderly officer despite his objection. He filed the judicial review in 2014 challenging the prison authority's rule for male offenders but not for females.

Leung's side argued that the rule constitutes sex discrimination, prohibited under the Sex Discrimination Ordinance or Article 25 of the Basic Law, by as "all Hong Kong residents shall be equal before the law."

The Commissioner of Correctional Services argued there could be risks that "long hair is used as a potential method of concealing prohibited items" to attack other inmates or for suicide.

"These risks are significantly higher in the male inmates population than the female inmates population," counsel for the commissioner said.

But Judge Au found the hair-cut rule was differential treatment based on sex, violating the Sex Discrimination Ordinance and Basic Law Article 25. "The commissioner's purported reasons are all based on stereotyped or generalized assumptions referable to the purported risks associated with male prisoners as a gender as a whole," Au said.

He said hair-cutting rules should be equal between genders, as he could not see why female prisoners should not have their hair cut for disciplinary or security reasons.

After the verdict, Leung quipped: "I hope I don't need to have my hair cut next time I am imprisoned."

The judgment will come into effect on June 1, allowing time for the department to implement mitigation measures.

A department spokesman said it is studying the judgment and will devise guidelines considering factors including security and religion in handling the hair cutting arrangement for male and female prisoners.

Leung has been wearing his hair long for decades, saying he would not cut his hair short until the Chinese regime rehabilitates those involved with the 1989 Tiananmen incident.

A source said in overseas examples, criminals hide drugs and forbidden materials in their long hair.

In 2015, there were 522 fights in prisons, among which 80 percent involved males, and if they were allowed to grow long hair, there could be hair-pulling during fights, the source warned.

But barrister Albert Luk Wai-hung said: "I don't believe the discipline would be much affected as the department has a perfect mechanism, just that one of its rules is under challenge."

A member and co-founder of the Ying Wa College Localism Association, Degas Chan Pui-chung, said there were also rules that boys should not have their hair over their eyebrows.

Studentlocalism convener Tony Chung Hon-lam said it was as unreasonable as schools should not interfere if boys' hair does not affect others.

Democratic Party lawmaker Ted Hui Chi-fung said he had his long hair cut short when he studied at Yan Oi Tong Tin Ka Ping Secondary School. The then-discipline master of his school, Ho Hon-kuen, the current Education Convergence vice chairman, cut it.

"It's reasonable that schools have some discipline, but people like Ho Hon-kuen have pushed things too far the other way. Hair should have nothing to do with conduct and academic results," he said.

Ho said last night that he could not recollect the incident, adding he would give money to students to get a hair cut. "Which schools would allow hair as long as Leung's? Boys and girls are different, just like boys should wear trousers and girls should wear skirts."