As confirmed by Tom Hiddleston, the immensely skilled actor who portrays Loki in the Marvel films, when Hiddleston referred to a conversation with “Avengers” director Joss Whedon:
In the end of “Thor,” when Loki essentially attempted suicide and fell into a dimensional wormhole between the realms, a kind of liminal “seventh circle of ***” (Hiddleston’s words), the temporal flow was different than it is in the “real” world, and he spent years there in total solitude staring at stars and supernovas and black holes and reliving over and over how terribly awry his life had gone before becoming lost. In this period Loki’s memories were severely distorted and he began to remember the last moments before he let go of Mjolnir’s handle in a warped way (for instance, he remembered Thor “throwing him” into the abyss rather than letting go himself while Thor frantically screamed his name, as he states in “Avengers”).
This was followed by being discovered by the Chitauri, who scried his most intimate thoughts and tortured him for sport and sent him to witness suffering and evil in every conceivable reality, realm, and universe (including earth, where he made contact with Eric Selvig and saw the Tesseract), and told him he was right in believing there was no value in freedom or love.
At this point Loki completely snapped. He bargained retrieval of the Tesseract for release onto Midgard, which the Chitauri were to, in turn, help him conquer. After contacting Thanos, the Chitauri agreed to this. Loki decided this was a win-win. Either he would rule Midgard and finally be a rightful king just like his brother and force his way into Asgard to get the Infinity Gauntlet for Thanos, OR he would fail, and be taken back to Asgard as a prisoner, and still get the Infinity Gauntlet for Thanos.
This explains many things about Loki. It explains why he was so sickly and gaunt when he returned to earth, as well as so much more markedly insane and cruel. It explains his belief in himself as some savior-pariah: “Freedom is life’s greatest lie” because the freedom to aspire as an individual is also the freedom to fail, to be found wanting, to be thought inferior: just as Loki himself was found inferior by his family and society. So essentially, Loki’s raison d’etre is a kind of warped and twisted megalomaniacal “philanthropy.” As Hiddleston put it, “Every villain is a hero in his own mind.”
Addendum: Because of this purgatorial experience in outer space, twilight and evening, and the appearance of a clear starry night sky in general, cause Loki to become nervous and depressed, though almost no one is aware of this.