Answer:
First, you will need 8 stars.
Once you have obtained the 8 stars, head to Princess Peach's play room and open the door that has a star with an "8" on it.
Once in the room, jump into the painting that has Mario on it. Travel to the top of the area and jump into the hole in the log. You will then be face to face with King Goomba, who you will need to defeat. After defeating him, you will receive a key with a Mario hat on it.
After receiving the key, go back to the central location of the castle. Head into the door on the top right of the stairs (1 star required), and go straight for the door with an "M" on it. Mario will come out as your character and Yoshi will be inside Mario's door.
Mario is now a playable character and can be switched back to Yoshi by entering his door again.
For a video tutorial, view the related link below.