President Judge Dan Pellegrini avoided the constitutionality of the law against same-sex marriage, rather focusing on the fact that a county clerk cannot independently decide which laws to abide by.
"A clerk of courts has not been given the discretion to decide ... whether the statute he or she is charged to enforce is a good idea or bad one, constitutional or not. Only courts have the power to make that decision," Pellegrini wrote.
Hanes began issuing the licenses after the Supreme Court ruled in June that the federal government must recognize legal same-sex marriages.
Critics assailed state Attorney General Kathleen Kane -- who refused to defend the state's ban on gay marriage -- and Montgomery County District Attorney Risa Vetri Ferman for refusing to hold Hanes accountable. The state's Health Department ultimately sued Hanes in August.
Hanes had argued the Pennsylvania ban was unconstitutional, and he therefore could not be compelled to enforce it. But the judge disagreed. Pellegrini also declined to address state Attorney General Kathleen Kane's refusal to defend the state's ban on gay marriage.
The ruling did not address the status of the 118 couples already married in Montgomery County. For 56 couples who received marriage licenses but had not yet wed, the ruling means they will not be able to file their completed certificates.
Supporters say that it's still progress for marriage equality in the state, as the married and licensed-but-not-wed couples now have standing to bring additional suits against the state.