Mr Justice Williams heard that a GP had recently discovered that the woman, who is in her 20s but has the mental age of a toddler, was pregnant.
He was told that a police investigation was under way.
The judge said the woman might have been raped or been made pregnant by a man who also had learning disabilities and a lack of understanding.
Police would carry out DNA tests in a bid to establish the identity of the father, he was told.
He analysed evidence 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.
Bosses at an NHS hospital trust asked him to allow doctors to perform a surgical termination.
A lawyer representing the trust said the woman had lived with foster carers for most of her life.
Barrister Eloise 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.
Miss 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.
Mr Justice Williams, who also oversees cases in the Family Division of the High Court, said authorising the termination of a pregnancy was a matter of "great moment" and a "significant interference" in a woman's autonomy.
But he said the woman's best interests were the "lodestar" of his decision, and evidence showed that allowing the pregnancy to continue would harm her.
Evidence showed that pregnancy was already affecting the woman's mental health and causing her to behave in a "somewhat more aggressive fashion".
She would have to go for intrusive medical examinations if the pregnancy continued, and would not be able to care for a child.
He said more than 30 professionals had been involved in the case and all thought termination was the right option.