From the Super Mario Wiki
If touched on the Touch Screen during gameplay, the blocks disappear and turn into the outline of a square, which the Mini Marios can walk through. The blocks that are erased become stockpiled on a small counter on the top screen. If this counter has any blocks in it, more Magnetic Blocks can be added onto the stage, even in different sets of blocks. However, if the outlines are touched again, they become full blocks, and the counter's number decreases. No more blocks can be added when the counter reaches zero, unless more blocks in play are erased. The Marios can walk on the Magnetic Blocks when they are set on the course to cross gaps and reach the goal, though. Since they are magnetic, Mini Marios can walk on them even if they are upside down or sideways. Unlike Pink Blocks though, Magnetic Blocks can not block the Minis' paths, as the Marios simply walk on the side of them when approached.
Magnetic Blocks can be used in the Magnet Mania kit, Spooky Attic Kit, Special Kit 2, and Special Kit 3 when creating stages in the Construction Zone.