From Sonic Retro
Capsules, otherwise known as Egg Pods or Egg Prisons, are where Dr. Robotnik stores the Animal Friends (or, in the case of Sonic CD, the Miracle Planet's plant seeds) that he's captured. Often found at the end of a zone, these ubiquitous containers acts as a 'finish line' for the player in that once it is activated, the level ends and the player's score is tallied. The animals are usually freed by jumping on a button at the top of the capsule, although in Sonic 2 (8-bit), which features a kind of floating egg prison, Sonic has to spin attack into the underside to open it.
Capsules appear at the end of every third act in Sonic 1 and Sonic CD, at the end of every second act in Sonic 2, Sonic 3 & Knuckles and Sonic Advance, and at the end of the boss acts in Sonic 4. They are also found at the end of Action Stages in Sonic Adventure.
In Sonic & Knuckles's Flying Battery Zone, the Doctor's skyship houses a great number of egg prisons which can be popped open during the normal course of the level. Instead of captured animals, these pods can contain rings, badniks, or even a cunningly-disguised sub-boss. Other capsules are empty, or the button may act as a spring. Finally, there's one in Sandopolis Act 2 that houses ghosts.
Sonic Advance 3 features giant capsules as a minigame. Here the prisons have multiple activation buttons arrayed over their surface, and pushing them quickly allows the capsule to be busted open faster. Freeing the animals quickly rewards the player with a number of extra lives proportional to the speed of completion.
In Sonic Lost World, capsules appear scattered throughout the level, and Sonic can open them to release the animals inside.