To get Luigi, you'll need to have Mario unlocked already. There's no exception to this rule — you simply can't get Luigi as Wario, unless you do a glitch, since he's the last character you can unlock. Don't forget to switch to Mario before starting this process if you haven't already done so. To unlock Mario, you'll need to have eight stars. Jump into the Mario portrait in the room connected to the minigame room as Yoshi, then battle the Goomboss in the level you're transported to. Once you defeat him, you'll get the Mario key. As Mario, head to the castle's courtyard. From the castle foyer, this is located through the plain wooden doors and down the long hallway. You'll know you're going the right way if you see a Boo (ghost) in the hallway. Once you're in the backyard, start killing Boos until one drops a metal cage. Then after you've already beaten the Big Boo, bump into the cage to enter Big Boo's Haunt. Note that you'll need to collect the first star in Big Boo's Haunt before you can get Luigi. The stairway to the second floor of the mansion (where the entrance to Luigi's level is located) only appears from the second star onward. Select the second star (or, if you have access to them, one of the stars after it). When the level starts, run into the mansion in front of you. Climb the staircase to the second floor and enter the door on the far right. You should enter a room with a raised wooden platform and a red "?" block. Break open the red "?" block. Mario should swell up like a balloon and start to float toward the ceiling. Float into the enclave and head through the door. Note that you can press the "R" button on the DS to cancel out of the floating move. In the Nintendo 64 version, getting up here proved quite challenging — many first-timers weren't aware of this door at first and had trouble getting to it once they found it. However, in the DS version, the balloon block makes  this much, much easier. In the next room, you should see a large portrait of Luigi. You know what to do — hop into the painting!

Summary:
Have Mario unlocked. Enter Big Boo's Haunt. Head to the second story of the mansion. Make your way to the attic. Jump into the Luigi portrait.