This is exactly what happened to me. I was scared to battle it because I didn't have any poke balls but then it said that it just joined my team and I screamed. And while This happened my dads friends were over so it just became weird
Pokémon Humor ~ If you pay close attention to the first seasons of Pokémon, Ash didn't beat most of the gym leaders. He would fight the gym leader, Team Rocket would show up, Ash and the gym leader would defeat Team Rocket, and then Ash would get a badge.