Mr Justice Holman made a ruling following a two-day Court of Protection hearing in London.
The judge had heard that the 37-year-old married woman was detained in a psychiatric unit under the terms of mental health legislation.
He said she could not be identified.
Health authority officials responsible for the woman's care had asked the judge to rule on whether she had the capacity to make a decision on terminating her pregnancy.
Lawyers representing the health authority told the judge that the woman had a ''chronic and severe mental disorder''.
Experts said she suffered from bipolar disorder - a condition formerly known as manic depression.
Mr Justice Holman heard evidence from the woman, a consultant psychiatrist involved in her care, from a lawyer representing her husband and from her mother.
The psychiatrist said he was ''100% certain'' that the woman lacked the capacity to make a decision about termination.
A lawyer representing her husband, who was at the hearing, said he agreed with the psychiatrist's evaluation.
Her mother also agreed with the psychiatrist and said she feared that her daughter might later regret seeking a termination.
The woman - who said she was not mentally ill but had suffered a "nervous breakdown" - told the judge that she wanted to divorce her husband and that he was "completely indifferent" when told of her pregnancy.
She said about two months ago she had started to think, "I don't really want the baby".
"I have no real support from my husband," she said. "It would never work. I don't really see a future in terms of my relationship with (him)."
She said medication had turned her into a "zombie" and she was very worried about her ability to care for the child.
"I have no money. I would not be able to work. I would be starting in a council flat on my own," she said. "The situation I am in, the idea of me having a baby. I think it is just crazy."
The woman added: "I would not regret that I got rid of it."
She said she would try to commit suicide if she was unable to terminate the pregnancy.
"I would seek to kill myself and the baby," she said. "I have pretty much had enough of the whole situation. The only way they could force me to have the pregnancy is by tying me down and locking me up."
Mr Justice Holman said in most cases in the Court of Protection, which is part of the High Court and analyses issues involving sick and vulnerable people, the views of psychiatrists on mental capacity issues were "determinative".
But he said that after hearing evidence from the woman he had reached a different view in this case.
The judge said he accepted that she was "mentally unwell" but he said the question was whether she was "incapable of making a decision".
"There is no doubt she has the capacity to make a decision," said Mr Justice Holman.
"It would be a total affront to the autonomy of this lady to conclude that she lacks capacity to the level required to make this decision."
He said even if some thoughts and views on her husband were "skewed" or "paranoid or delusional" she had given many other reasons for her desire to terminate the pregnancy.
The judge said the woman had said she was unhappy in detention and asked him to imagine being "unhappy and pregnant".
"It seems to me to be a perfectly understandable position for detained pregnant mother to take," he added.
"It has not been established that she lacks capacity to make decisions about terminating the pregnancy."Suggest a correction