A ban on religious symbols such as headscarves “may be justified by the employer’s need to present a neutral image towards customers or to prevent social disputes”, the European Court of Justice said in a statement.
The employer must also show it is not discriminating between different beliefs and religions in its policy, the court said.
The two women, a cashier in a chemist and a special needs carer, had taken their cases to German courts after being prohibited from wearing headscarves at work.
The German courts had then referred the cases to the ECJ for an interpretation of EU law.
The woman working at the chemist had been employed there since 2002 and had initially not worn a headscarf, but had wanted to begin wearing one after returning from parental leave in 2014.
However, the chemist instructed her to come to work “without conspicuous, large-sized signs of any political, philosophical or religious beliefs”, the ECJ said.
The second woman was employed in 2016 as carer at a non-profit association and had initially worn a headscarf at work.
She too went on parental leave, during which time the association issued a policy prohibiting the wearing of visible signs of political, ideological or religious conviction in the workplace for employees with customer contact.
After returning from parental leave, she refused to remove the headscarf, which resulted in several warnings and eventually in her being dismissed.
National courts must examine in each individual case whether company rules are compatible with national laws on religious freedom and the need for a “policy of neutrality”, the ECJ said.
There must be “a genuine need on the part of the employer” for such a policy, it said, and it must also not go against “national provisions on the protection of freedom of religion”.