Justice Holman, sitting at Court of Protection in Birmingham Tuesday, said her husband lacked capacity to consent to a sexual relationship.
"The fact that they are married to each other would be no defence. If she were to have any form of sexual intimacy with him, he would be the victim of a criminal act," he said in his ruling.
The woman, who cannot be named for legal reasons, had pleaded with the court not to annul her marriage to the man who is being cared for at a local authority home in the West Midlands.
Sandwell Metropolitan Borough Council had asked the court, which makes decisions on behalf of those deemed to lack capacity, to declare the marriage not recognised in England and Wales as the man lacked capacity to consent to the marriage.
However, the judge gave in to the woman's request and declined to annul the marriage, noting her wish to remain a wife and the pleasure her husband derived from her frequent visits to see him.
It is believed to be the first time that a British judge has allowed a marriage to continue despite finding that by law it never existed because the man lacked the capacity to consent to, or contract, a marriage.
The judge expressed sympathy for the woman.