From the Super Mario Wiki
The Rocket is an item in Super Mario Bros. 2. It can be randomly plucked from the ground, just like Vegetables, and acts as the "door" to the next level, taking Mario, Luigi, Toad or Princess Peach upwards. After a certain height, the player's character jumps out of it, and it explodes shortly afterwards. It only appears in Worlds 4 and 7 of the game. In the Super Mario-Kun adaption, Mario, Luigi, Yoshi, and Toad defeat Clawgrip with a rocket.
Rockets make their latest appearance in Super Mario 3D World. After defeating Meowser in World Bowser, the Sprixie Princesses will build a rocket in World 1 leading to World Star in space. Rockets are also appeared at the end of the World Star and World Flower, which leads to the next world after the players have met the requirements.