This is how Optimus and Twilight lose their memories goes in One Shall Rise Part 3.
[Megatron gets up, rubs his head, then looks at Twilight and Optimus]
Megatron: Teamwork? Ha.
[Megatron approaches the two, sword drawn]
Optimus Prime: Where are we, Megatronus?
Twilight Sparkle: And what happened?
[Megatron looks confused for a moment, then realizes what's happened. He puts his sword away and helps the two to their feet]
Megatron: Don't you remember, old friends?
[The door falls down]
Bulkhead: Optimus, you alright?
Applejack: You okay, Twi?
Optimus Prime: Why did he call me that?
Twilight Sparkle: And why did she call me Twi?
Arcee: What did you do to them?
Rainbow Dash: Yeah.
Twilight Sparkle: Who are they?
[Decepticon Groundbridge appears]
Megatron: Our mortal enemies. We're outnumbered. Go, I'll cover you.
[Before entering the Groundbridge, Optimus and Twilight look back at Bumblebee and Rarity. Bee bleeps something and Rarity just stares wide-eyed. Optimus and Twilight then go into the Groundbridge]
[After a short battle with them, Megatron enters the groundbridge. Ratchet bridges the team back and they have a little conversation]
Ratchet: Optimus and Twilight. Are they...?
Arcee: Dead? No.
Bulkhead: But they looked right at us without recognizing us. Didn't even know their own names.
Ratchet: If Twilight and Optimus did not know their own names, they lost more than just the collectable wisdom of the Primes and Alicorns. They lost their own memories.
Bulkhead: Are you serious?
Rainbow Dash: Whoa.
Ratchet: I know it may seem downing right about now but we need to pull through it. With or without them.
Applejack: Don't say that.
Rainbow Dash: Twilight. [looks up]
Knock Out: Welcome back, Lord Megatron.
[Breakdown sees Optimus and Twilight and charges]
Megatron: At ease, Breakdown. That is no way to welcome long lost comrades. Orion Pax and Nightfall Twinkle are one of us.
[To be continued...]