Baneboo's Lost Object!? - S7-E39
Continuity mistake: When Ash tells Corphish to use Bubble Beam after Team Rocket's Pokémon during the first battle, his bag disappears. This also happens when Ash tells Torkoal to dodge Cacnea's Needle Arm. (00:07:52 - 00:19:02)
Answer: He is a good guy but just found himself in a bad situation when he worked for Lysander. He didn't want him to harm Ash and his Pokémon when he was trying to get the special bond between Ash and his Greninja to work. He does leave Lysander and go back to being a good person.