The ruling ended some lengthy legal battles over the differential treatment facing same-sex couples.