Early on there was some speculation that the various incidents Korra was experiencing were helping her to unblock her chakras in the order that Pratik described; you will note that she was able to see more and more of Aang's memory as the season went on. In the final episode she turned away from worldly attachments, as evidenced by pushing away her friends and family; at that time, the only thing she wanted was to be the Avatar.
Attaining an epiphany in the depths of despair is not such an uncommon occurrence, and when you're the Avatar, it's established that such epiphanic revelations can come in the form of contact with your past lives. The problem isn't that it happened, but some more insight into Korra's spiritual state would've made it clearer why it was happening.
It's incorrect to call it a deus ex machina, because the mechanism behind it was previously established and highly relevant in the first series.