The ruling involved a Nigerian man subjected to tests by Hungarian authorities, which the court said had interfered unduly in his private life.
"An asylum seeker may not be subjected to a psychological test in order to determine his sexual orientation," the European Court of Justice said.
"The performance of such a test amounts to a disproportionate interference in the private life of the asylum seeker," added the Luxembourg-based court.
The asylum seeker had applied to Hungarian authorities for asylum in April 2015 saying he feared persecution because of his homosexuality.
Homosexuality is illegal in religiously conservative Nigeria and further laws against gay marriage and same-sex unions were passed in 2014.
Australia sends dozens of refugees from Pacific camps to US
Hungarian authorities rejected his application after a psychologist's expert report they had commissioned did not confirm his alleged sexual orientation, the court said.
The refugee took the issue to the Hungarian courts, saying the tests "seriously prejudiced his fundamental rights" and could not assess his sexuality in any case.
The EU court ruled that states can order expert reports to help determine their need for protection but that they must respect European rights laws.
It found that the impact of sexuality tests were "disproportionate", adding that "such interference is particularly serious because it is intended to give an insight into the most intimate aspects of the asylum seeker's life."
Hungary rightwing government is a fierce opponent of mass migration and has rejected compulsory refugee quotas imposed by the European Union.
COMMENTS (1)
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ