I have personnally witnessed a precident to this when I worked for the Army as a civie administrator; I once saw a WO2 (SgtMaj) shout and scream at a full army Captain for telling him how to do his job. As I recall the Captain was in charge of an Artillery battery and the WO2 was chief clerk and the RQMS.
Gotta correct you on that. A WO2 is a Chief Warrant Officer, while a Sergeant Major is a noncommissioned officer... aka senior enlisted. These are two totally different things.
Warrant officers are an odd thing... and are pretty close to what you mention. They're contracted (or "warranted") rather than commissioned (which is what officers are) or enlisted. They're still held accountable, yes, but they fall outside either the enlisted or officer chains of command.
My first job, after graduation from my OBC, was as the battalion S4 for the 107th MI BN. I was a 2LT at the time, and I had two warrant officers working for me, running the BN motor pool. Good guys, very unmilitary... to them it was a job, not a profession. The fell outside of the chain of command... ie, they really had no authority to give orders to the enlisted folks under their command, on their own steam. So it worked like this... I ordered the (enlisted) folks who worked in the motor pool to follow the "instructions" given to them by our two "master-mechanic" warrant officers. So in theory, the orders that these guys were giving were MY orders. But since I didn't know diddly squat about running a garage, they were acting on my behalf. They had no authority of their own... sort of like how a babysitter has no personal authority over the kids he or she babysits... only the authority granted to them by the parents.
Fortunately, I had a great relationship with my two motor pool chiefs and was respected by the NCOs over my motor-pool enlisted guys, so things went well. But if you got an officer into that position who didn't have good relationships all around, or if you had a warrant who thought he "deserved the authority himself" and didn't play by the rules, well... that can cause trouble. Because these guys don't have any "authority of their own." NOT a situation I'd want to find myself in...
A Sergeant Major, on the other hand, is a totally different thing. He has a LOT of authority. And while a Sergeant Major is technically outranked by even a 2LT, only a total idiot would try to play that card.
NOW... why'd I just go through that? Well, it's because your anecdote has two TOTALLY DIFFERENT MEANINGS, depending on whether this was a warrant officer or an NCO.
A warrant officer can do what you just described, and the worst that can happen to him is to get fired. But a warrant officer is normally not going to to that because he has no authority of his own.
On the other hand, an NCO who did what you just described, and in PUBLIC no less, would be immediately subject to Article 15 proceedings for insubordination, and SHOULD be court-martialed over it (especially if it's happened more than once). Of course, a Sergeant Major would not hold the position you describe... Sergeant Majors are generally the senior enlisted person in a Battalion (sometimes), or more commonly with a Regiment or a Brigade. They're basically at the same level as the unit commander, and generally report ONLY to the commander (who would be either a Lt. COL or a full Colonel). They would NEVER be found in a "clerk" type job.
It's very common for senior NCOs to "correct" junior officers, or even company-grade officers like the one you mention. "Officially" they can't do that... because the lowest-ranking commissioned officer technically outranks the highest-ranking NCO. So there's a way to do it. I never minded my NCOs giving me advice, or even telling me that I was "fucking up." But not in public, not in front of the troops. I had one guy do that (and he was wrong in that case anyway)... a senior NCO who was closing in on retirement. He challenged me repeatedly, in front of the troops, and was just generally insubordinate (he was around 50 and I was late 20s). I wouldn't have minded him talking with me, PRIVATELY, like that... but what he was doing was intolerable, and I had no choice but to file charges and, as a result, he left the service at a reduced rank. This was HIS doing, not mine... I simply acted to prevent him from undermining my authority, which was necessary for me to do the job I was required to do.