From Castles in Japan, by Morton S. Schmorleitz (Tuttle, 2011), Kindle Loc. ~460ff:
In December 1614, [Tokugawa] Ieyasu gathered together a large host and laid siege to the castle in what is known as the Winter Campaign. In less than a month the two sides came to terms in which [Toyotomi] Hideyori agreed to allow the outer defenses of the castle to be destroyed as a gesture of his good faith. The Tokugawa forces went a bit further, however, and also filled in the inner moat.
Soon after the besieging army left, Hideyori again began to gather troops at the castle. When he ignored Ieyasu's command to cease this activity, the Tokugawa forces again descended on Osaka. This was the opening of the Summer Campaign, which began in May 1615 and ended early in June when the besieging forces fought their way into the castle. Hideyori committed suicide, bringing an end to the Toyotomi Clan. The Tokugawa were now supreme. Ieyasu died about a year later, but he had laid a foundation that gave his descendants rule of Japan for over 250 years.
The period of history just discussed might be referred to as the golden age of castle building, starting with Nobunaga's Azuchi Castle, which was designed as a fortification to resist forces armed with the matchlock. Its high stone walls, deep wide moats, corner towers, and tall donjon were intended to cope with this new weapon. At the same time the castle's design enabled defenders to use firearms to best advantage. Next came Hideyoshi's castle at Osaka, even more formidable and impregnable. These two structures set the pattern for later castle construction. (Note: It is thought that the Portuguese helped with the design of these two fortresses.) Most castles and castle ruins extant today were built in the short three-decade period from 1580 to 1610, employing the architectural design of the Azuchi-Momoyama period. It was then that Kato built his fortress at Kumamoto with its high, imposing walls, Ikeda greatly improved and enlarged the small castle at Himeji, and Ieyasu took the small castle at Edo and developed it into one of the largest fortresses in the world.
Shortly after Sekigahara, Ieyasu called upon the tozama ["outsider"] lords to contribute heavily to the building of Edo Castle. These lords were those who were not related to, or had no hereditary tie with, the Tokugawa family and had remained neutral during Sekigahara or submitted to Ieyasu thereafter.7 In addition to Edo Castle, they were also compelled to build other castles including those of Nijo, Hikone, Nagoya, and Sumpu [in Shizuoka], and to enlarge and remodel still others. Most of these castles were located in strategic areas between Kyoto and Edo and were built on the pretext of providing for national defense. Most, however, were never used in the kind of warfare for which they were designed. The building program was undertaken to reduce the resources of the tozama daimyo, whom Ieyasu did not trust, and to keep them under control.
Policies were also laid down by the Tokugawa government to control the tozama daimyo in ways other than financial. Castles were not to be built, remodeled, or repaired without permission from the shogunate. Men of the samurai class were obligated to live in the castle town. This requirement, an extension of Hideyoshi's sword hunt, tended to strengthen the feudal system. Marriages between the daimyo families had to be approved by the shogunate to prevent hostile alliances from developing, Tokugawa vassals were placed in fiefs where they could observe the activities of their tozama neighbors and report any evidence of conspiracy to Edo. They were moved frequently to prevent them from becoming too well established and forming alliances.
The daimyo were permitted to govern their fiefs without much interference from Edo, but they were obliged to observe the regulations imposed by the shogunate. Although they were allowed this freedom, they were required to alternate residence between their fiefs and Edo. This policy, known as sankin-kotai, was designed to prevent them from conspiring against the Edo government. While they were away from Edo, they left their families there as hostages. The traveling to and from Edo was another form of control, for the daimyo were expected to travel with a huge retinue, thereby incurring expenses that sapped their resources.