An NHS trust spent more than £600,000 on a legal battle against eight nurses who complained about sharing changing facilities with a transgender colleague.