A judge has given doctors permission to perform a caesarean section on a woman with mental health problems if she becomes agitated during labour and loses the capacity to make decisions about how her baby should be born.

The woman has been deemed to have the mental capacity to make decisions and has told doctors that a caesarean section is “the last thing she would agree to”, Mr Justice Hayden heard.

But lawyers representing hospital officials responsible for her care said the woman was heavily pregnant and could go into labour at any time. They said she had depression and a history of experiencing psychotic episodes.

Lawyers said she might become agitated and lose the mental capacity to make decisions during labour. If that happened, they said, doctors would have to act quickly and needed to know that they could legally perform a caesarean section without the woman’s agreement if necessary.

The judge analysed the case at a hearing in the court of protection, where issues relating to people who might lack the mental capacity to make decisions are considered. He said the case was exceptional and the order he had been asked to make was “draconian”.

He said issues relating to whether doctors should override the wishes of people if they lose the capacity to make decisions were rarely considered. But he said the interests of the woman were paramount and doctors must be able to do what was needed to preserve her life and the life of her child.

He concluded it would be in the woman’s best interests to allow doctors to deliver the baby by caesarean section against her will if such a move was necessary. The woman, who is in her 30s and being cared for in London, could not be identified in media reports of the case, the judge said.

Officials at Guy’s and St Thomas’ NHS foundation trust, who have responsibility for the woman’s obstetric care, and those at South London and Maudsley NHS foundation trust, who have responsibility for her psychiatric care, had asked the judge to make a ruling.

Bridget Dolan QC, who led the legal team representing the two NHS trusts, said the woman had been diagnosed with bipolar affective disorder.

“Whilst the view currently is that [her] impairment or disturbance in the functioning of her mind or brain – ie bipolar affective disorder – does not impair her capacity to consent to obstetric treatment, her consultant psychiatrist is of the opinion that there is a substantial risk of her condition worsening close to or during labour, to the point where capacity is impaired,” she said.

“Anticipatory orders and/or declarations are therefore sought to enable the lawful provision of such care and treatment as is clinically indicated, including emergency caesarean section, to [her] and her unborn child to ensure their health and safety and to minimise the risk of any significant and long-lasting harm.”

The woman was not represented by lawyers at the hearing. The judge, who also hears cases in the family division of the high court, said the urgency of the situation meant the application had been made at short notice and there had not been enough time for the woman to instruct lawyers or for lawyers to be instructed on her behalf.

The barrister Parishil Patel QC appeared at the hearing without instructions to guard her interests. He acted as an amicus, or “friend of the court”.