close except where you say “an officer cant sleep with somebody under their command, but the officer could still sleep with that person if they wanted to - theyd just lose their job.”
They are subject to the UCMJ and there have been plenty of cases where officers have gotten much worse then “losing their job” for fraternization. Including fines, jail time, loss of rank, Bad Conduct Discharges (which are punitive and carry a severe burden when attempting to find a job outside), etc
So when they signed on to be an officer they knew what the conditions were and if they weren’t willing to live with that they will suffer penalties.
Any employer can stipulate the behavioral conditions for employment. If there’s a rule that you don’t talk about your sex life or leanings at work, that’s a rule that can be made by an employer. The difficult part for the military is that the employees bunk together so if there’s a rule about behavior it impacts so much of the employee’s life. But that’s a condition of employment that the person knows before they sign up for the job - just like the condition that superiors not sleep with their subordinates. It’s a free world; they can sleep with who they like, but that doesn’t mean it will be without consequence in their employment.
Is that your understanding?