The court ordered the release of the woman from a centre run by the Maiti Nepal group, which has been championed by British actress Joanna Lumley and Hollywood star Demi Moore, the lawyer who filed the court case said.
"The court determined that Maiti Nepal was detaining Rajani Shahi on the grounds that they wanted to provide her counselling to change her sexual orientation," Hari Phuyal told AFP.
The woman, Shahi, 30, claimed in the case that she left her husband because she was attracted to other women. Seeking her return, her husband petitioned Nepal's National Women's Commission to get her back.
"The shelter is found (to be) ultimately control-oriented," the court decision said, ordering that the woman be released.
More From This Section
The Maiti Nepal group and its founder have won international acclaim for their work in combatting human trafficking from Nepal, where an estimated 12,000 girls are trafficked each year into India's lucrative sex industry.
The group's founder, Anuradha Koirala, was awarded a "CNN Heroes Award" for her work in 2010, which the American news channel gives annually.
Actress Lumley serves as an ambassador for Maiti Nepal, and Moore hosted a television programme called "Nepal's Stolen Children" highlighting the organisation's work.
An activist said the women was detained for 50 days.
A spokesperson for Maiti Nepal said he could not comment on the court's decision but that the organisation had taken Shahi in based on the recommendation of the National Women's Commission and police.
The commission welcomed the court's decision, but said they were surprised to be implicated in it.
"We are glad the court ordered her released if that's what she wanted, but we do not work on the basis of whether a woman is heterosexual or homosexual so we are shocked at the allegations," commissioner Mohna Ansari told AFP.