The decision marks an end to a years-long legal and moral dispute that made it all the way to the U.S. Supreme Court.