In order to gain access to Worlds 4 and 7, you must defeat the Bosses of worlds 2 and 5 to open up their respective worlds as Mini Mario. To defeat the boss in that form, you will have to use ground pounds and precision aim in order to not miss.
Then, when you beat the boss, you will drop into the
small crack in the floor and continue to World 4 or 7 instead!