The Code of Bushido
The characters never talk about the code of bushido here, but it's a vital part of the story, both in how it shows up and in how it's broken. It's similar to the code of chivalry, dictating the behavior of knights and European noblemen, only it's got that Land of the Rising Sun vibe that makes it unique to Japanese culture.
It formally arose in the Edo period of Japanese history, in the early 17th Century after the events that take place here. But it existed long before then in a more informal form and Kurosawa definitely had it in mind when he made this movie. With Japan defeated in World War II and learning how to move past that, it was probably on a lot of Japanese citizens' minds as well.
The code itself stresses eight ideals or virtues, which samurai are supposed to follow until the day they die: Benevolence, Courage, Respect, Sincerity, Righteousness, Honor, Self-Control and Loyalty. By following them, a samurai could fulfill his duties to his lord and to Japanese society as a whole. In a lot of ways, a samurai's worth was determined by how well he followed the code: a constant never-ending test to show the world how a hero was supposed to behave.
Here's where things get interesting.
Bushido dictates that if a samurai fails in his duties, as the samurai in this film clearly have, then they are required to commit ritual suicide (called seppuku) in atonement. Seppuku is regarded as an act of courage, which essentially erases any shortcoming or mistake the samurai might have made.
Except that the samurai in this movie haven't done that.
They're ronin, which means they've lost their lord (or abandoned him) and now serve no master. That's a serious no-no in Japanese society, and represents their inability to meet the code which they presumably dedicated their lives to. They've already failed in their duty. We're meeting them while they're picking up the pieces and trying to move on.
And yet the code still defines them, at least in part, because they show bravery and loyalty to each other and their cause. They take on the bandits because it's the right thing to do—not because they're winning any honor or glory—and maybe because it makes them feel like the samurai they were instead of the mercenaries they've become.
That lends them a sense of tragedy that makes them much more interesting than simple heroes. These guys have already lost their mojo through suffering and failure that we don't get to see in the movie. Their task here reflects the code they once followed and continue to follow as best they can. But they've seen the limits of that code. They know that bushido couldn't answer all of their questions and ultimately that they weren't willing to commit suicide to uphold it.
Bushido guides their actions here, but also reminds them that they can never live up to what it demands. Nothing they do will be good enough. But they continue on, doing the best they can and accepting the good they can do as well as the failures they have to live with.
That idea held a lot of power for a country that just lost a major war. They could feel the pain and tragedy of these characters even as they cheered on their heroics, finding a way to live with what they previously thought was unlivable. Bushido defined the limits of all of that: hanging over the characters like a sad little rain cloud and echoing Kambei's final words: "The farmers have won. Not us."