From the Super Mario Wiki
Spiked Balls are objects first found in Super Mario Bros. 3 - where they are spit and thrown by the Spike creatures -, and later appear independently in the Super Mario Land series, as well as in the New Super Mario Bros. games. They usually appear in castle levels acting as obstacles, rolling around and smashing anything in their way. Ball 'n' Chains are Spiked Balls with chains attached to a pivot swinging in circles. In Super Mario Bros. 3, New Super Mario Bros. Wii, and New Super Mario Bros. U, Spikes produce spiked balls and throw them at players. A sub-species of Spike called Stone Spikes produce and drop spiked balls made of stone at players.
In Super Mario Land 2: 6 Golden Coins, large metallic spiky balls appear to be floating in the final level, Mario's castle, which is taken up by Wario. This is not their most signifiant appearance in the Super Mario Land games; the spiked balls later return in the first Wario Land game, where they are preponderant in the Parsley Woods. This game marks the first time spiked balls are seen rolling towards the player. Also, they are always imprevisible, as they plummet from the trees' thicket unconditionally. However, unlike in their future New Super Mario Bros. appearances, the spiked balls will stop whenever they hit a wall.
Spiked Balls also appear as obstacles in Wario World. They appear in the various obstacle courses found inside Wooden and Steel Trapdoors, and are also used as weapons by several enemies and bosses in the game. Cractyls drop them instead of Bombs in later stages, and SandWorm also spits Spiked Balls at Wario as one of its attacks. In this game, they are colored dark blue and have long spikes of the same color.
A Giant Spiked Ball is a larger version of the Spiked Ball also found in New Super Mario Bros. They, like their smaller counterparts, are almost indestructible, except to Mega Mario or Mega Luigi. They are usually found in castles and can also destroy anything it rolls over, including the smaller Spiked Balls. In New Super Mario Bros. Wii Giant Spiked balls are found only in the World 8 where they appear in World 8-2, and World 8-Airship where Bowser Jr. uses them as exploding weapons against Mario. However, Mario can use them against him by Ground Pounding the ground to throw them into the Koopa Clown Car 3 times. In New Super Mario Bros. 2, both Spiked Balls and Giant Spiked Balls reappear. A pair of very large Spiked Balls appear in the World Mushroom Castle. Icy Spiked Balls appear in World 4-1. One can be found in World Mushroom-A which helps Mario obtain a Star Coin. Spiked Balls also feature in the battle against Morton Koopa Jr., where Morton fires them from his wand to attack Mario/Luigi. In New Super Mario Bros. U, they are replaced by Grrrols. However, there is a giant variation called Ball 'n' Chain which is a giant Spiked Ball on a string with spikes. Spiked Balls do appear when a Spike throws them. Both Spiked Balls and Giant Spiked Balls (under the name Spikey Balls) return in Super Mario 3D Land. They function very similarly to the preceding games. They can be destroyed by Statue Mario and invincibility.
Spiked Balls reappear in Captain Toad: Treasure Tracker once again being tossed by Spikes.
Spiked Balls also appear in Mario Party 4 in the minigame Hop or Pop. They also appear in several minigames in Mario Party 9. In the minigame Bumper Bubbles, players must try to collect balloons while avoiding Spiked Balls that fall onto the screen from above; hitting a Spiked Ball results in a player's bubble popping, which causes all their balloons to be released and for them to fall off-screen. They also appear in the minigame Tumble Temple, in which the players must avoid the Spiked Balls and Giant Spiked Balls that roll through several pegs from above; hitting one results in that player being eliminated. Additionally, in Chain Event, players must slide down chains, flipping from one side to the other to avoid Spiked Balls. The minigame Spike-n-Span also involves one player hitting the platform above to roll a Spiked Ball in the direction of the other players. They're also in Spike Strike were the player must use a hammer to send the Spiked Balls back at Spike. It also appears in Mario Party 10 in the Minigame Spiked Ball Scramble and in Bowser's Painball.
In Paper Mario: Sticker Star, Spiked Balls only appear whenever a Spike opens its mouth.