The woman in her 20s had been married for five years, but had been forced to relieve herself in nearby fields.
Indian law only allows divorce in limited circumstances such as domestic violence or proven cruelty.
The woman's lawyer told the AFP news agency that the judge said forced open defecation was a form of torture.
The court, in the state of Rajasthan, said that women are often forced to wait until dark to travel to the open fields used instead of toilets.
A report carried by the Times of India quoted the court's judgement as saying: "We spend money on buying tobacco, liquor and mobile phones, but are unwilling to construct toilets to protect the dignity of our family.
"In villages, women have to wait until sunset to answer nature's call. This is not only physical cruelty but also outraging the modesty of a woman."
Indian media said the woman had filed for divorce in 2015.
Urination and defecation in open fields is common in parts of rural India. The government has set a goal to provide every household with a toilet by 2019, but the work has been met with some resistance.