Here his how Dijon switched sides and SpongeBob takes his stand against Merlock in The Tale of The SquarePants Master Ship Builders.
Titanic: (locked up in a steeled cage) You can't leave us here like this, Merlock!
Merlock: Silence! For what you are about to witness is the end of all that is good!
Britannic: You won't get away with it, Merlock!
Merlock: I already have. Prescott! guard the elements from intruders!
Gremlin Prescott: Yes, Merlock!
Spiny: Duh, What's the plan now, Captain?
Captain Bonemeal: We're taking over Equestria in the name of us Bone Pirates and Merlock!
Kolestra: And we get the share of the rewards Merlock offers.
Ribbs: My thoughts exactly, Let's go!
Princess Luna: Do not despair, My friends. No one can take away our hope nor our courage.
Princess Celestia: Well said, Little Sister.
With the crew.
SpongeBob SquarePants: Dijon, Why are you doing this?
Dijon: Because Merlock ordered me too. He was an honorable master I've ever served.
Rarity: Are you out of your mind, Dijon?
Apple Bloom: Dijon, What if Merlock use you?
Scootaloo: All he cares about was himself and no one else.
Sweetie Belle: If he destroys everything in Equestria. Not only it'll hurt Everyone and Everypony. It'll hurt you too.
Discord: They're right, Dijon. And besides, After all the mean things Merlock did to you, You still think he's honorable?
Dijon: Yes, Despite that he got a genie turning me into a pig.
Discord: Dijon, Don't make the same mistake that I once made. When I was sent to capture Tirek, He once offered me something even more valuable then friendship. I've gathered all the Earth Ponies, Pegasi and Unicorns for Tirek to feast their magic, flight and strength out of them. I thought I could trust him after he gave me Scropan's medallion as a sign of his gratitude and loyalty. But when I gathered Applejack, Fluttershy, Pinkie Pie, Rainbow Dash, Rarity and Spike, Tirek feast the magic out of them. I then realized that there's nothing worth more then friendship. Tirek betrayed me and feast my every last magic and turned his back on me. And Dijon, Maybe Merlock will turn his back on you too.
Dijon: Oh, What is Dijon doing!? (lets Discord out) You're free to go, Discord.
Discord: Yes! Ha ha! Now, For my Grand Finale! Bibbidi...! (snaps) Bobbidi...! (snaps) Boo!
When the crew was freed.
SpongeBob SquarePants: We're free!
Patrick Star: But, What're we going to do now, SpongeBob? Merlock must be taking over Equestria right about now!
SpongeBob SquarePants: (takes a stand) I won't let him get away with this!
Plankton: Neither are we, SpongeBob! If you're going, It's good enough for us!
SpongeBob SquarePants: Let's take him down.