Employers that sack workers for being gay or transgender are breaking US civil rights laws, the Supreme Court has ruled.