The Supreme Court said the conviction by the military court did not take into account whether the defendants' relations, which took place in a personal space, were consensual, and thus excessively restricting their right to sexual self-determination.
"Punishing these incidents could ... infringe upon the right to equality, the dignity and value as human and the right to pursue happiness as guaranteed by the Constitution," the Supreme Court said in its ruling.
Homosexual activity is not illegal for South Korean civilians but same-sex relationships for men in the military have been subject to criminal punishment.
The ministry of defence said it would thoroughly review "the intent of the Supreme Court's ruling". In the past, South Korean authorities have defended the military code against same-sex relationships as necessary to maintain discipline.
The two defendants were indicted in 2017 for having same-sex intercourse in 2016, while off duty and outside their base, which is punishable with prison for up to two years under the Military Criminal Act.
Human rights groups have for years called on South Korea to decriminalize same-sex relationships for men in the military, warning that laws fuel violence, discrimination and stigmatization against gay soldiers.
"This Supreme Court ruling will serve as a milestone in the long debate over this law," the Center for Military Human Rights Korea said in a statement.
The military act is under review in the Constitutional Court after the filing of numerous petitions against it, and the center urged the court to quickly complete its review of what it called an "outdated and bad" law.
The death last year of South Korea's first known transgender soldier triggered debate over how members of sexual minorities in the military are treated in a country that requires all able-bodied men to serve for at least 18 months.
The soldier, Byun Hui-su, was found dead at her home a year after being discharged for undergoing gender reassignment surgery.
Our Standards: The Thomson Reuters Trust Principles.