A London coroner has been ordered by the High Court to change her "cab-rank" queuing policy for handling burials after it was ruled "unlawful".
Senior coroner Mary Hassell had said she would not fast-track inquests based on religion.
Under Jewish and Islamic law, bodies must be buried on the day of death or as soon as possible afterwards.
Her jurisdiction covers north London which is home to large communities of orthodox Jews and Muslims.
Lord Justice Singh said the policy set by Ms Hassell was discriminatory and must be quashed.
Sitting with Mrs Justice Whipple, he said: "We hope that, with appropriate advice from others, including the chief coroner and perhaps after consultation with relevant bodies in the community, the defendant can draft a new policy which meets the needs of all concerned, including protection of the legal rights of all members of the community.
"We are hopeful that a satisfactory solution can be found in this sensitive area."
Lawyers representing religious groups, who brought the legal challenge, argued Ms Hassell's stance ignored "deeply held beliefs" of certain religious communities.
They said Ms Hassell's policy was unlawful and breached the Human Rights Act and the Equality Act.
BBC's religious affairs producer Callum May
This case will not set a precedent for coroners across the UK.
Each coroner has discretion over the order in which bodies are released.
In Mary Hassell's case, the High Court decided she was acting unlawfully by refusing to ever consider religion as a reason to prioritise the release of a body.
Two judges, Lord Justice Singh and Mrs Justice Whipple, said a coroner was "entitled to prioritise cases, for religious or other reasons, even where the consequence of prioritising one or some cases may be that other cases will have to wait longer for a decision."
The chief coroner for England and Wales has been asked to give advice to Ms Hassell, and for her to consult Muslim and Jewish communities, before drafting a new policy.
The court previously heard the coroner's patch covered the boroughs of Camden, Islington, Hackney and Tower Hamlets, which between them have "sizeable" Jewish and Muslim minority populations.
Following the court's ruling, Board of Deputies vice president Marie van der Zyl called on Ms Hassell "to consider her position."
"She has previously said that she does not believe that using her discretion to order cases, which she needs to do to uphold the religious freedom of the diverse communities she is meant to serve, is 'fair'," she said.
"If she cannot carry out this basic function of her role, she must vacate her position.
"Whatever the future for the inner north London coroners' service, the issues raised by this case have highlighted the lack of accountability for this public service and the pressing need for reform."
High Court hopes Mary Hassell, inner north London coroner, can now draft new policy “that meets the needs of all concerned” with advice from chief coroner and communities. Court rejects her request for legal advice: courts don’t tell decision-makers what to decide. Summary here: pic.twitter.com/m0N3NDrblW— Joshua Rozenberg (@JoshuaRozenberg) April 27, 2018
Abdul Hai, a member of Camden Council's ruling cabinet, described the court's decision as a "resounding victory for those who have campaigned for the coroner's service to be brought into the 21st Century".
"Over the past five years, the coroner has lost the confidence of the large sections of the communities in the four boroughs.
"It is essential that she takes immediate action to rekindle that confidence," he said.