Debug mode is earned through Stamina battles. Win 54 of them, and win 6 against the Ice Climbers and 6 against Bowser, with the difficulty set to level 6.
It is a grind rather than a puzzle, so set aside a decent block of time. Once unlocked, debug mode gives you the developer tools left in the game — stage and character spawners, damage and state manipulation, and a look at assets that never made it into a normal match.