Kingdom Hearts Birth by Sleep
Castle Oblivion was initially the world Land of Departure. After the defeat of Master Eraqus at Terra's hand, Master Xehanort summoned the darkness to destroy the land. Aqua would later bring a comatose Ventus to the Land of Departure to keep him safe. As Aqua walks into the dilapidated castle, she remembers a "secret" that Master Eraqus told her when she became a Master. He told her that he was the protector of the world and that if anything ever happened to him, she should seal the world's keyhole with the Keyblade to prevent darkness from taking over the world. She was also advised to recreate the world so that only she knew the structure and layout of it and that any unwelcome visitors would be "lost in oblivion".
As a result, she used Eraqus's Keyblade to seal the world's keyhole and recreated the world into Castle Oblivion. She then leaves Ven in the newly-formed Chamber of Waking and promises to bring Terra back with her before waking him up. When Aqua departs from the building to go look for Terra, she turns around to look at her new home, where the player first sees the newly-transformed exterior and recognizes the world to be Castle Oblivion.
Between Kingdom Hearts Birth by Sleep and Kingdom Hearts: Chain of Memories
The castle was eventually found by Xemnas of Organization XIII, who decided to convert it into a second headquarters for the Organization. It was intended to be a place to research memories, an important topic to the Nobodies of the Organization, who have only their memories to form personalities with. Xemnas sent Xigbar and Xaldin to recruit more members for the Organization, as they needed a large group in order to run the castle.
According to a flashback in Kingdom Hearts II Final Mix that takes place in between Kingdom Hearts Birth by Sleep and Kingdom Hearts, Xigbar and Zexion discussed the new castle and the Chamber of Repose, which housed Aqua's armor and Keyblade, that Xemnas constructed in Radiant Garden while he was Xehanort, and which he frequently went to. Xigbar believed that Xemnas was looking for the complementary Chamber of Waking, and that this place might be somewhere in Castle Oblivion.
Eventually, a strange Nobody named Naminé appeared in the castle and was found by the Organization. She soon became the center of their research, due to her strange abilities of memory manipulation. In order to further research, pods were developed that could be used to piece together memories. Xemnas had entrusted the castle and Naminé to the neophyte Marluxia, but he would soon plot to use this power in a bid to seize control over the Organization. While Marluxia and his associates, Larxene and Axel, controlled the top half of the castle, the senior members Vexen, Lexaeus, and Zexion controlled the basements. Throughout their appearances, they are shown to have a strong rivalry.
Kingdom Hearts: Chain of Memories
After defeating Ansem, Seeker of Darkness, and restoring the damaged worlds, Sora, Donald Duck, and Goofy find themselves in a grassy field with the King's dog, Pluto. They follow Pluto along the path to Castle Oblivion, and as soon as they enter the castle, they forget all of their skills and are forced to rely upon the castle's memory-based card system. Though Marluxia and Larxene tell them their memory loss is simply the nature of the castle, it is revealed that the mysterious girl Naminé is actually the one reshaping Sora's memories, so that Marluxia can use Sora as a puppet against Xemnas. The scheme fails thanks to the meddling of Axel, who frees Naminé, and Marluxia and Larxene are destroyed at Sora's hand. Sora then uses one of Xemnas's pods so that Naminé can restore his memories, and is eventually moved to Twilight Town.
Meanwhile, Sora's friend Riku awakens from the darkness within the lowest basement of Castle Oblivion, where he faces the remaining darkness of "Ansem". Though he initially sets out to destroy the indelible darkness in his heart, with the help of DiZ, Naminé, and King Mickey, he is able to eventually embrace both the light and the dark, achieving balance. The three basement members, Vexen, Lexaeus, and Zexion seek to recruit Riku in order to counter Marluxia's use of Sora, but Riku denies their requests and vanquishes them. Riku eventually defeats the Ansem in his heart, and decides not to have Naminé seal it away completely; instead he sets out on the "road to dawn" in order to help while Sora is sleeping.
Kingdom Hearts 358/2 Days
Kingdom Hearts 358/2 Days takes place between Kingdom Hearts and Kingdom Hearts II, and so in this game many of the castle's secrets are revealed. After members of Organization XIII are sent to Castle Oblivion (which starts the events in Kingdom Hearts: Chain of Memories), Roxas learns from Demyx and Xigbar that the members assigned to Castle Oblivion were annihilated. Xion later goes to Castle Oblivion seeking answers about her existence. Axel tries to stop her, but his efforts are futile. Later, when Roxas learns from Axel that Xion was born in Castle Oblivion, he becomes determined to investigate the place for himself. However, barely has he walked in the door when he is overcome by a strange weakness and passes out entirely, due to how close he physically was to Sora and Ventus.
During conversations between Axel and Saïx, Saïx asks Axel if he has found the Chamber of Waking, to which Axel replied that it was difficult to find since Castle Oblivion is huge and it is currently unknown if that room was ever found. It is also revealed that Axel would be sent various times by Xemnas to find the room, showing Xemnas's extreme determination to find the Chamber of Waking, yet he never could. Aqua, as per Master Eraqus's suggestion, had specifically designed the castle for its secrets to be known to nobody but herself. Thus, Aqua's design led Axel to be "lost in oblivion".
Kingdom Hearts II
The Castle's inside was seen in the opening credits of Kingdom Hearts II, featuring Sora's battle with Marluxia, Riku's battle with Ansem, Naminé's placing Sora in the Memory Pod, as well as several other important events in Kingdom Hearts: Chain of Memories illustrated in full computer graphics. The outside of Castle Oblivion was briefly shown in Roxas's final dreams, as Sora's memories end as he opens the door.
Kingdom Hearts Coded
After defeating Sora-Heartless and returning to the data worlds, Data Sora enters a data version of Castle Oblivion. He has meetings with the mysterious cloaked man, as well as various figures from Sora's memories. Like the real Sora did, Data Sora uses World Cards to traverse the castle. Near the end of the story, he meets Data Naminé, who explains the reason of his existence.
Kingdom Hearts 3D: Dream Drop Distance
Ventus continues to sleep within the Chamber of Waking, following the end of Sora and Riku's Mark of Mastery exam. Upon Sora's return to Traverse Town, he smiles from Sora's happiness.