Three men, including a Ugandan and one from a Muslim country, failed in their bids for asylum when a Dutch court said they had not proved their sexuality.
EU states including the UK have been criticised for their handling of gay asylum requests.
The European Court of Justice (ECJ) says they must respect human dignity.
Its rulings apply to all EU member states.
The case is significant across the EU because of a surge in the numbers of sub-Saharan Africans seeking asylum in Europe this year. Most African countries treat homosexuality as a crime.
The Czech authorities were criticised by the UN, EU and human rights activists in 2011 for using an erection or “phallometric” test – a practice dating back to communist times – to determine whether certain asylum seekers were gay…