First off, I want to clearly state that these are simply theories and I’m working through my own thoughts still. Also, that this is not justifying Loki’s actions, but merely attempting to analyze why he did what he did. Here are the points I’d like to make:
Loki is flawed but his flaws are a result of a culmination of poor (if partially unconscious) treatment by his parents (mostly his father), his brother, and his peers. He is both a victim of circumstance and his own foolish actions.
Loki’s motivation is desperate desire for self-respect.
Loki is not a villain. He is not a hero. He is an anti-villain.