The surgery was the latest setback to President Trump’s effort to bar transgender people from serving in the military.