Mr Justice Williams ruled the woman's pregnancy could be terminated after analysing the case at a hearing in the Court of Protection, where judges consider issues relating to people who lack the mental capacity to make decisions, in London on Friday.
A lawyer representing hospital bosses said a surgical termination would be performed this week.
The judge heard how a GP had recently discovered that the woman, who is in her 20s but has the mental capacity of a toddler, was pregnant.
He was told that a police investigation was under way.
The woman might have been raped or been made pregnant by a man who also had learning disabilities and a lack of understanding, the judge said.
Police would carry out DNA tests in a bid to establish the identity of the father, he was told.
Bosses at a NHS hospital trust responsible for the woman's care had asked him to allow doctors to perform a surgical termination.
Barrister Eloise Power, who represented hospital bosses, said the woman had lived with foster carers for most of her life.
Ms Power said the woman's foster parents were Christians and churchgoers.
But she said the couple were sure that an abortion was in the woman's best interests.
Ms Power said medical specialists and council social workers involved also all agreed that a surgical termination was the right option.
Mr Justice Williams said medics could restrain the woman in order to administer a general anaesthetic if necessary.
The judge said the woman, who lives in the north of England, could not be identified in media reports.
He also said the names of the hospital and council involved could not be revealed in case that information created a jigsaw which pointed to the woman's identity.
Stay up to date with the latest news stories from a Christian perspective. Sign up to our daily newsletter and receive more stories like this straight to your inbox every morning.