Yeah, he does cross the line at times. I suppose it's to Spock's credit that McCoy doesn't get written up, just one-upped.
I've always maintained that Spock must have personally ensured that neither Boma nor McCoy was court-martialed after "The Galileo Seven." In my head canon, Scotty - the absolute model of a Starfleet officer - made a full, unvarnished report to Kirk, who then went to Spock and asked why Spock's report mentioned none of the xenophobia displayed by Gaetano, Boma, and McCoy. Spock then asked Kirk to take no action, and Kirk (after due consideration) agreed.