A closet is a single square located behind a door. Often the door is a secret door.
Closets are referred to as niches in the source code.
Sometimes closets are generated without doors leading to them. The only way to get to these is for a corridor to be generated adjacent to them, or to teleport or dig in. Such closets always have a scroll of teleportation inside, and a potion of object detection will reveal its presence. Every closet has either a door or a scroll of teleportation.
There is sometimes writing in the dust outside. The engraving ad aerarium (from the Latin "to the treasure") indicates that the closet contains a vault teleporter, and the engraving Vlad was here indicates that there is a trap door inside. On deeper levels, a closet marked with ad aerarium may have a level teleporter instead. This is a pun on a secondary meaning of "aerarium" as sky.
Monsters can be generated inside closets just like on any other square.