I have a Magby that I caught and every time I bring it out in battle, a star appears on it. What does that mean? It doesn't happen for any other Pokemon I have.
Your Magby is shiny. Congratulations!
A shiny Pokémon is a rare (1/4096) colour variant version, and displays a little star when it's sent out in battle. Other than that, there is no difference between a shiny Pokémon and its normal counterpart.
To confirm this, you can check your Magby's status page, you should see a red star near its model.
Your Magby is a rare alternate color Pokémon, also known as a Shiny Pokémon. Congrats on catching one!
Shiny Pokémon have a different appearance, but are otherwise the same as their regular counterparts. Aside from the alternate color, you know that they are Shiny because they have a sparkle when they come out and a star on their status screen.
In Generation 7, the odds of finding a Shiny Pokémon in the wild is 1 out of 4096. The Pokémon company has written a guide on SOS chaining indicating that the odds of finding a shiny Pokémon increase in SOS Battles the more wild Pokémon are called. You have to have a whopping 70 Pokémon get called into the battle before you get the best odds: 1 out of 1024. This answer on the site has more information about the odds.
You can also increase your odds by getting the Shiny Charm, which you can find at the GAME FREAK office in Heahea City after you complete your Pokédex.
Usually, only player-obtainable Pokémon are Shiny. Earlier games had some trainers in battle facilities (e.g. Battle Frontier) that had Shiny Pokemon. Sun and Moon introduced the first trainer outside of that with a Shiny Pokémon: Sightseer Marcus in Seafolk Village and his Exeggcute. So you'll never see a gym leader suddenly come out with a Shiny Pokémon.