NHS managers must balance the needs of trans staff with the need for single-sex spaces, the first minister has said.