Spinning the cape at the start causes magikoopa to spawn out of the way. Alternatively, duck-jump on magikoopa immediately when the level starts for safety.
Let go of the d-pad before hitting the p-switch, then neutral jump off the turn blocks in order to maintain full speed.
Video: Lemmy's Castle - Cape Source: Sten
95 Exit, No Cape
Without a cape, manipulating Magikoopa to spawn on the bottom is different. Start holding left when entering the level, and switch to right as soon as Mario appears.
Additionally, jumping up to the P-switch is more difficult with Magikoopa in the way. A safer strat is just to stomp Magikoopa at the start of the level.
Video: Lemmy's Castle - No Cape Source: Dotsarecool