Imperial Japan seemed to hold immense respect for the Samurai and many of their values seemed to be upheld in the society, particularly the in the army. For example, the Japanese soldier's "Banzai charge" and their belief that they should end their own lives rather than being shamed by being captured. I can even remember watching a documentary (The World at War) where a Japanese pilot refers to his plane as his equivalent of a Samurai's sword.
Imperial Japan itself was a nationalistic nation. Meaning you can look at Germany and Italy for a historical example. Simply put the Germans after WW1 were demoralized and starving, so they looked to the halcyon days of the past for guidance (where Hitler came in with his Aryan theory) and moral strength. Mussolini in Italy used the rhetoric of empowering Italy to a second Roman empire to get himself power.
In Japan it was sort of the same thing, since Japan itself was becoming afraid of Western Influence (the radio, mass produced consumer goods etc) and sought to create an identity to ensure Japanese culture would survive. This in tandem with increased Japanese nationalism and a desire for more land (hence the invasion of China) meant that the Samurai Code was resurrected and heavily edited for consumption of the populace. It showed how in serving your master well and acting with discipline you brought honor to your family and ancestors. Which meant that a good citizen is an honorable and respected citizen.
The Samurai Code in the army went the same route since following your superiors and their orders brought honor to yourself and your family, so soldiers followed said orders to the letter (no idea about why Nanking happened though).
There is a misconception however about your Banzai charge. The true Banzai is nothing like that of what you see in films, a true banzai is silent and terrifying. Soldiers would grease their weapons and insert cloth strips so nothing would glint or make a single noise, and as one they would run into American lines. This meant that when the Americans heard the first "BANZAI!" they Japanese were literally already on, in and behind them with their bayonets, tearing them to pieces. Can you imagine the terror they felt when all you see is a mix of Japanese and American bodies? Not knowing who you can shoot or who you cant since friendly fire was too big a risk, but if you didnt shoot you had to go melee which was even more risky. This also happened often at night which made things even more terrifying.
However as the war progressed Americans learnt that the will of the Banzai was its commanding officer i.e. the one with the sword and shooting him would quickly demoralize and destroy the Banzai itself. As the experienced officers died, the Banzai disintegrated into the big mass charges you see on the movies.
The reason that the soldiers killed themselves is because of the rhetoric they were fed from day 1, i.e. Americans would torture and kill them for enjoyment. So rather than surrender they often fought to the last man. As a counterpoint wounded soldiers were often killed so that they couldnt surrender by officers later in the war. Also the shame is a part of it, if the officer did not order a surrender and you surrendered, you brought shame upon your family (which in asian cultures is a massive massive taboo).
In reference to the plane being a samurai sword i dont have knowledge of this but i do know why soldiers held themselves to the Samurai standard. The standard soldier was issued a bayonet that was often just as if not more important than their actual weapon, since the bayonet was to the common man what the sword was to a samurai. The samurai code with reference to swords and the like is complicated but it boils down to "die on your feet, do not be captured since that is humiliating, fight with honor". The fight with honor is subjective since Oda Nobunaga heavily used gunpowder weaponry to crush his enemies but thats another story.
I think thats everything, for more clarification please ask.
EDIT: Forgot to talk about seppuku. Its a ritualistic suicide method by which you take your short sword and disembowel yourself. Its done so that you can die honorably and your foes cannot capture you and bring shame to you or your family (many lords and officers killed themselves this way.) Keep in mind it can take upwards of 15 minutes to die during which your stomach acids will attack your flesh and your guts open up which smells horrible. Not recommended.
Hello! I'm not sure if this answers your question, but Edward Drea's Japan's Imperial Army: Its Rise and Fall, 1853-1945 (Lawrence: University Press of Kansas, 2009) has an interesting comment on the supposed "Samurai spirit" embraced by the Japanese leadership. I'll quote him here in full:
Ordinary soldiers did not fight ruthlessly to the bitter end because of a common samurai gene pool or military heritage. The great paradox is that the only samurai the new Meiji leaders ever trusted were themselves. Appeals to a mythical warrior ethos were government and army devices to promote the morale of a conscript force that neither the civil nor military leaders held in much regard.
In macro terms, soldiers fought because the educational system inculcated a sense of national identity and responsibility to the state, patriotism, and reverence for imperial values that the army in turn capitalized on to indoctrinate pliable conscripts with idealized military values. At the micro level, they continued to fight when all hope was gone for various institutional and personal reasons. Army psychologists identified tough training, solid organization, army indoctrination, and small-unit leadership as factors in sustaining unit cohesion in extremis. Personal reactions were as varied as the conscripts. Some fought to uphold family honor (usually sons of veterans), others simply to survive one more day, and most to support others. Based on recent, preliminary research, it appears that the vertical solidarity between junior leaders (lieutenants and senior sergeants) and the conscripts they led played a more significant role in combat motivation than in western armies. (258)
On the psychological aspects, Drea cites a Japanese-language article by Kawano Hitoshi. For a English-language summary of his findings, see his chapter "Japanese Combat Morale: A Case Study of the Thirty-seventh Division," in The Battle for China: Essays on the Military History of the Sino-Japanese War of 1937-1945, ed. Mark Peattie, Edward Drea, and Hans van de Ven (Stanford: Stanford University Press, 2010], 328-56.
I hope you find this helpful! :)