I assume this comes from nobles being officers. So that even inexperienced nobles would be, say, lieutenants, and thus outrank more experienced and capable commoners, like sergeants. How has this evolved over time, and why does it persist? How does treatment differ? (For example I know the Geneva Conventions have rules against making officers work, and I know even officer POWs, like in Coldizt, were assigned enlisted soldiers as servants)
The legal distinction is that officers are commissioned by Congress (or the Queen, or whatever depending on the country) to command the Army on its behalf, enlisted personnel are -in- the Army. As a result, after I graduated OCS, I received discharge papers effective the day I took the Oath of Commissioning. There are practical differences as well, for example, U.S. Officers have to pay for their own food and uniforms., enlisted personnel are issued it. (There are some exceptions, but it's a general rule)
The history is indeed rooted in the noble/serf structure. It then evolved through to "people who are better educated", shall we say, as, being representatives of Congress, they were expected to better use their knowledge to not only lead men, but to make more complicated decisions in the interest of the nation as opposed to just fighting and discipline. The way I've always viewed it, officers figure out what needs to be done, NCOs figure out how to get it done, and junior enlisted are the main folks to do it.
As for the perks, again, I suspect a holdover. The U.S. Army is probably the most egalitarian military in the world. Unlike other countries I've worked with, the U.S. Officer has far fewer "perks of privilege by position," Example, I was liaising with a French unit, the junior enlisted served us dinner on the Regimental china flown in from France, while we sat on proper, solid chairs at a good table. Meanwhile, at my home base, officers ate in the same chow hall as everyone else, at the same long tables as everyone else, on the same cheap furniture as everyone else, and sat interspersed with the enlisted folks. And had I instructed one of my junior enlisted to serve me dinner, I probably would not want to have eaten it. It's not that we don't have any "rank privilege", but it's far less than it used to be. (Note, there's a difference between ceremoniously serving dinner, and "Sergeant, I'm massively busy with this, would you please go and grab me some food?"). We no longer have officer's clubs, and so on.
Between 1965 and 1984 or so, the Chinese Army (PLA) actually abolished all ranks as part of the Cultural Revolution. I have no idea how the Army worked, but apparently not too well given that they went back to a traditional rank structure.