Thomas doesn't like Gally because he regards him as an arrogant, domineering bully. He takes exception to the fact that Gally introduces himself as the real leader of the Glade and insists on being called "Captain Gally." Thomas responds to Gally's vainglorious outburst by giving him an exaggerated salute, hoping to show him up in front of the other boys.
Thomas doesn't yet know his way around the Glade, and so it's understandable that he doesn't want to appear weak in the presence of such an intimidating boy as Gally. In challenging Gally, Thomas is putting down a marker, making it abudantanly clear to Gally and to everyone else that he's not someone to be pushed around, even if he is a newbie in this neck of the woods.