"Banshu"(a guard) is a person who keeps watch at night as part of guard group (ban). In a more limited sense, it refers to a person stationed in an office of the bakufu (Japanese feudal government headed by a shogun) who stood guard for the seii taishogun (literally, "great general who subdues the barbarians") and his palace.
It is said that Banshu in the bakufu originally derives from the fact that in the time of MINAMOTO no Yoritomo and the Kamakura bakufu, he arranged for gokenins (immediate vassals of the shogunate) with skill in bow and arrow to stay close to him night and day. After MINAMOTO no Sanetomo was assassinated, Kozamurai dokoro (the Shogun's guard) was set up, and a system of Koban (small watch teams) was created, which consisted of 6 teams on a rotating 24 hour watch. Under Koban, there were several sub-teams such as Kinjuban (a bodyguard for the shogun), Hisashiban (a person who keeps night watch under the eaves of building), and Moshitsugiban (a post to attend to visitors), and the powerful gokenins' sons were appointed. They formed a shogun kinshuso (a class of shogunal bodyguards), which sometimes became a counterweight to the regent's power, and provoked political conflicts.
In the Muromachi bakufu, the same system was used, and later it developed into the Hokoshu (the shogunal military guard), which was made up of five teams. They not only guarded the shogun but also played a central role in the military force directly controlled by him, with privileges granted by the shogun, such as Kyosei (the right to direct tax payment of tansen, a kind of provisional tax imposed on the Imperial or shogunate family's estate and his private estate and paid to the bakufu without any intermediaries such as Shugo) and sanctuary from interference by Shugo. In addition, the concept of Banshu came to be applied to the status of samurais and their family ranking, and based on this concept job titles such as Shobanshu (officials who accompany the shogun), Otomoshu (a group that accompanied the shogun to Kyoto), Moshitsugishu (a person in charge of conveying messages to the shogun), and Naidanshu (judges) were created.
Also, in the Edo bakufu, the Muromachi system was retained as one of the good practices of samurai families, and part of it was used in the system of Hatamoto/Gokenin (direct vassals of the shogun and vassals of the shogunate, respectively). That is to say, the Banshu system was incorporated into the valet and guard posts such as Shoinban (castle guards), Sojaban (an official in charge of ceremonies), and Tsukaiban (a person responsible for order and patrol in the battlefield).