Massachusetts appeals ruling on prisoner sex change