The court upheld a ruling that legalized same-sex marriage in California and struck down the federal Defense of Marriage Act that denied federal benefits to same-sex couples already married in 12 states.