Thanos took Loki, because he saw an Asgardian from the royal family trying to destory a planet. Half of Jotunheim had been destroyed by the bifröst and this is exactly Thanos ideology. Our purple grape had no background information about the reason behind this action and Loki probably never told him the truth. Thanos only thought that he found someone who had the same motives like him. Maybe the mad titan even knew about the past of Asgard and Hela and assumed that Loki would be like that, too. But when he figured out, that Loki actually didn't wanted to ally with him, he started to torture him. He was tortured with the mind stone, that's out of question since Thanos only had that stone and I think that the stone showed him his worst nightmares, the same like Wanda used her powers to manipulate the Avenger's minds. At the end, Loki was broken and ready to do everything for Thanos to stop this and that's how he ended up with attacking New York.
I would say that the nightmares were all about Lokis heritage. Probably involving every 'what if...' scenario if Asgard should find out. Thanos was probably never able to figure out what it was what Lokis resistance finally ended and he didn't knew that Loki only wanted to destroy Jotunheim cause he had, technically, an identity crisis and was desperate. And that's why he called Loki in IW an Asgardian. Loki never told him about his true heritage. He just played along, trying to survive.
Loki probably tried to gain Thanos trust, but when he was told what the plan of the mad titan was, he became rebellious and that's when he told Thanos that he won't help him to complete his plan to collect all Infinity Stones.
In IW when Thanos attacks the refugee ship. Loki knew that he wouldn't survive. Thanos would hunt him down and kill. He probably played with the thought to just run away using the Commodore, but that would only have meant to leave Thor behind. Thanos would have used Thor probably to get Loki out of his hiding since he knew that he even would sacrifices an Infinity Stone for his brothers life. When he was off screen, I bet that he was running away, but turned half way, cause he knew that this move would increase Thor's chances to survive. He decided to sacrifice himself for Asgard and Thor. That's why he's so cocky towards Thanos when he came back. He wanted to make his last seconds alive a show, something that the mad Titan would remember. He also decided to tell Thanos without hesitation, that he actually is the rightful king of Jotunheim, also telling him this way that he completely misunderstood him. It wasn't his plan to destroy the frostgiants, because he thought he had to.
I think, that Thanos was a bit confused about this revelation. He had expected someone who understands him, but Loki just smashed it in his face that he was wrong. Telling Thanos that he would never be a God just proves this, and also prophesies that Thanos can't win this battle. He can't act like a God, because he doesn't understand what it means to be one. Our little Trickster just tells Thanos in a pretty extraordinary way that his plan is completely idiotic and that he would have done it completely different as a God.















