During the opening scene of Avengers: Infinity War we see Loki completely uninjured as if he wasn't present on the ship of which we know that he was. Why wasn't he injured like Heimdall, Thor, and the rest?
Loki was a prisoner of the Black Order at the start of Avengers: Infinity War, likely by choice. Loki is not a fighter and so it doesn't make sense for him to get into a big battle with people who are fighters. Instead his talent lies in being a trickster and being sneaky.
Ebony Maw joined the Black Guard as they surrounded their prisoner—Loki, the God of Mischief himself.
Avengers: Infinity War - Novelisation
We see this later on after he has given up the Tesseract to Thanos, he starts trying to play the double agent again. He tries to make it seem as if he is Thanos' ally and then strike at the last second to take him down. And it almost worked if Thanos hadn't already had the Space Stone.
Loki: I consider experience, experience. Almighty Thanos, I... Loki... Prince of Asgard... [looks significantly at Thor] Odinson... the rightful King of Jotunheim... God of Mischief... do hereby pledge to you, my undying fidelity.
Avengers: Infinity War
So, he wasn't injured because he probably didn't join in on the fight, had he joined in, he would have been injured similar to Thor and Heimdall.