After the whole ordeal with Queen Chrysalis and her changeling army, Twilight found herself disillusioned with the concept of friendship. Her friends and Princess Celestia turned their backs on her when she tried to warn them about Cadance not being the kind and loving mare she remembered. Her older brother got a pass since he was technically being brainwashed by Chrysalis, so he was the only pony she forgave for his actions. The others weren't being controlled like that, so they didn't have an excuse. Since the whole ordeal was considered to be settled after Cadance and Shining Armor married, nothing was truly resolved between anypony. Celestia refused to answer to her role in the fiasco and Twilight's friends didn't want to talk about how poorly they treated her when they should've listened.
When the Crystal Empire returned, Twilight and her friends are sent to help Shining Armor and Cadance protect it from Sombra. Because she still felt the pain in her heart from the wedding fiasco, Sombra used his dark magic to invade her mind. Rather than use force to manipulate her, he offered to be her shoulder to cry on in an effort to manipulate her. After hearing about the failed changeling invasion, Sombra began telling her lies to poison Celestia's influence over her. Fooled by Sombra's false kindness (although Sombra later realizes that he actually was being sincere), Twilight vowed to help Sombra get his kingdom back, thinking that it would be better off under the tyrant's rule since he was better at protecting his subjects than Celestia. Upon finding the Crystal Heart, Sombra told Twilight how to bypass his security system so she could take it. He told her she could take the relic to Cadance and protect the kingdom from him or do nothing and let him sieze control. To Spike's shock, Twilight throws him into the trap Sombra set for anypony who managed to find the Crystal Heart and runs off to help the dark unicorn. She then approaches her friends and tells them she's chosen to side with Sombra and uses Celestia's negligence as her excuse. She also plays the royal wedding rehearsal card to manipulate her friends into joining her and Sombra. Applejack, Rarity, and Fluttershy don't listen, but Twilight manages to sway Rainbow Dash and Pinkie Pie into fighting for the dark unicorn. Everypony else escapes and informs Celestia that the Crystal Empire was lost and that the Elements of Magic, Laughter, and Loyalty had turned against Equestria.
In the months that follow, Sombra takes Twilight under his wing and teaches her dark magic. Since her special talent is magic in general, she quickly masters the subject and becomes a powerful user of dark magic second only to the Crystal King himself. During their lessons, they also find themselves falling for each other. Sombra was much more gentle and kind than Twilight ever thought he'd be (meaning he wasn't the monster she was led to believe) and Sombra found Twilight to be as beautiful as she was powerful and intelligent. The dark unicorn asks his student to be his wife and queen, to which she accepts.
Edit: I fixed up Queen Twilight's gown. It has a darker look to it and better matches Sombra's regalia.