The ruling came after an appeal against the ban from a Muslim association in the northern state of Lower Saxony, which “intends to carry out Friday prayers… in the remaining weeks of the fasting month Ramadan”, the court said in a statement.
Given the “serious infringement of religious freedom” caused by the ban, it was “hardly tenable” that there was no possibility to apply for an exception, it added.
The court ruled that an exception should be granted if “an increase in the risk of infection could be reliably denied”.
It listed possible ways that the mosque had suggested of lowering the risk of infection, including a lack of singing, masks for the congregation and marking areas reserved for prayer.
It added that the infringement of religious rights was “particularly large with respect to the Friday prayers during Ramadan”, though the ruling also applies to “churches, synagogues and other religious communities”.
Germany introduced a ban on religious assembly as part of its first package of measures to slow the spread of the coronavirus back in mid-March.
Though the federal system means there are some exceptions, most states have upheld the blanket ban, and the constitutional court's ruling in the Lower Saxony case will set a national precedent.
The ruling comes as Chancellor Angela Merkel and regional state premiers prepare to meet to discuss the current coronavirus measures on Thursday, with religious services high on the agenda.
Germany began to lift some lockdown measures from last week, allowing shops under 800 square metres to re-open.
The easing of restrictions prompted calls for further relaxations, including from religious groups.
Yet the constitutional court said that shops and religious services “should be judged differently”, as there was much greater scope for differences in the size and structure of religious services.
Any exceptions should be granted according to how effectively protective measures could be enforced, the size and structure of the religious community and the current risk level in the local region, it said.