This is how Twilight becomes infected goes in The Enemy Within The Sparkle.
[At Canterlot, Princess Celestia and Princess Luna are with Twilight as Thunder Streak and Starlight come in]
Thunder Streak: Any luck finding out what happened?
Starlight Glimmer: Or what those things are?
Princess Celestia: Not yet.
Princess Luna: But something seems to be the matter with Twilight.
Starlight Glimmer: What is it?
Princess Celestia: We're not sure.
Princess Luna: Looks she's been infected with some kind of virus.
[Stormer and Trixie come in]
Trixie Lulamoon: Twilight, thank Celestia you're alright.
Stormer: A virus? Let me see.
[Stormer checks Twilight]
Stormer: This is no virus. This is a series of tiny nano-bots which can turn anyone against their friends and hold that person against their will.
Twilight Sparkle: Put me inside a shield before whatever Meltdown did to me takes over. [coughs] Too late.
[Twilight looks away. She snickers sinisterly and she turns around and her eyes have turned green. Starlight and Thunder Streak and Trixie prepare magic beams]