From the Super Mario Wiki
Doors are objects usually found in many houses and castles in the Mario games, first appearing in Super Mario Bros.: The Lost Levels. Most doors allow the player to continue on with the level, while others, usually hidden, will lead to secret areas. If a door is locked, a key must be used to unlock it.
In Super Mario Bros. 2, doors are very common in Subcon. Some doors appear when Mario, Luigi, Princess Toadstool or Toad throw a Magic Potion to the ground. These doors lead to Subspace, an area where the characters can find a Mushroom or coins (or Yoshi Eggs in Super Mario Advance). Some normal doors are locked and can be unlocked if the player finds the hidden key in the level. If they find it, they must carry the key back to the door to unlock, whilst avoiding the Phanto pursuing the player. They often have a Skull on them and go to a reverse of the current area.
Doors also appeared in the later Mario platformer games: Super Mario Bros. 3, Super Mario World, Super Mario 64 (and the Nintendo DS remake Super Mario 64 DS), Super Mario Sunshine, New Super Mario Bros., Super Mario Galaxy, New Super Mario Bros. Wii, Super Mario Galaxy 2, Super Mario 3D Land New Super Mario Bros. 2, and New Super Mario Bros. U. In Super Mario 64 and its remake, Mario uses doors to explore and visit different areas of Princess Peach's Castle and different levels. The doors in the side-scrolling platformers are usually found in fortresses, Ghost Houses, castles and towers. The larger doors lead to bosses. In the 3-D platformers, doors are found in many different places Mario or Luigi visit. In the Super Mario Galaxy games, some doors require keys so they can be unlocked. After Mario or Luigi collects the key, the door will immediately open.
There are several doors in Luigi's Mansion, in which a majority of them are locked in the beginning. Luigi must collect keys from chests to open them and access new rooms. Sometimes when doors are locked, thorns cover them, and this usually indicates the entrance to a major area, although they may spontaneously appear to trap Luigi in a room, such as the Anteroom and Mirror Room. When Luigi attempts to open a thorny door he takes damage. Another notable type of door is a Trapdoor, which when opened causes Luigi to be slammed into a wall and flattened, causing him to take damage and lose coins.
Doors also appear in The Super Mario Bros. Super Show!, if the Mario Brothers, Toad, and Princess Toadstool defeats him, King Koopa will use a Magic Potion, making his escape in episode like "The Unzappables", "Mario Meets Koop-zilla", "Bad Rap", and "The Adventures of Sherlock Mario".
In Super Mario World 2: Yoshi's Island, Yoshi's Island: Super Mario Advance 3 and Yoshi's Island DS, large blue and white doors are found throughout Yoshi's Island, as well as locked ones. Yoshi must find the key to unlock the locked doors. In King Bowser's Castle in Super Mario World 2: Yoshi's Island, there are four numbered doors spinning around, which all lead to different areas of the level and eventually leading to the final area. If Yoshi throws an egg at a door, the others will disappear, leaving the door hit by Yoshi available and to be entered.
Doors also appeared in other series of games, such as the Donkey Kong series, Wario series, Paper Mario series and Mario Party series. Doors appeared in Mario cartoons, movies and comics as well. The plot of Paper Mario: The Thousand-Year Door in particular revolves around the large and mysterious eponymous Thousand-Year Door and the quest for the seven Crystal Stars that would open it. Super Paper Mario also features three living doors, called Dorguys. Paper Mario: Sticker Star feature Secret Door stickers, which when placed on a door outline in a level using Paperize mode, they'll lead to special rooms, most of which contain Things.