From the Super Mario Wiki
Retrieved from "https://www.mariowiki.com/index.php?title=Mario_Key&oldid=2615713"
The Mario Key is an item in Super Mario 64 DS. It is the key that unlocks the door that Mario is trapped behind and the only character key required to beat the game. The Mario Key was used by Goomboss to trap Mario behind a door in Princess Peach's Castle after capturing him. It is obtained by Yoshi after collecting eight Power Stars, entering the room behind the Princess's Rec Room, and defeating Goomboss inside the Mario portrait.
The key is about the size of Mario, is made of gold with a large M in the center of it, and has Mario's Cap on top of it, though the cap disappears upon collecting it. Once Yoshi retrieves this key and brings it to the door Mario is behind, Mario will be freed, and Mario's Caps appear inside courses if the player is someone other than Mario.