I think that she was Celestia's student for a while, got angry at Celestia, and then found the portal. Already knowing about Twilight, she knew that at any moment, Twilight would be given the crown. So, during Sunset's final year, she decides to attack her in the pony world and then return to the human world. This is my hypothesis.