What'd you want him to do, magically free Loki before hitting him? It was an outburst of emotion as a result of Loki shit talking someone Luffy idolizes, something Loki did purposefully to provoke Luffy as Pew pointed out, this isn't even new for Luffy, he punched the shit out of Vivi in the pre-timeskip because she said something he disagreed with for example.