What are the principles (if there are any) behind the conservation of bending moment in frame analysis?

I notice from this question that the moments at joint connection are somehow "conserved", or being "transferred" from one element to the others. In other words, there are no "missing moment".

Note that at joint for left image:

$$2.767\text{ kNm}=(2.37+0.397)\text{ kNm}$$

And for bending moment diagram that I examined so far (using structural software), this seems to be always the case.

So I wonder whether this relationship is true for all kinds of joint connection? Or is there a deeper physics principle behind it (such as the conservation of energy)? How can we derive it from the first physics principle, if it there is a first principle?

Well, such an equilibrium (be it of moment, or shear or axial force) is necessary for any static system, and can be trivially demonstrated with Newton's second law. For forces, that is the classic $F=ma$ (force equals mass times acceleration), while for moments it is equal to $M = I\alpha$, where $M$ is moment (or torque), $I$ is the rotational inertia (also known as the moment of inertia with dimensions $ML^2$, as opposed to the moment of inertia we commonly discuss in structural engineering, with dimensions $L^4$, which is usually called the second moment of area), and $\alpha$ is the rotational acceleration.
If you could calculate the force at a given point as equal to anything other than zero, that would mean that the entire system would accelerate in the net force's direction according to $F=ma$ (if $F\neq0$, then $a\neq0$). Equivalently, if the total moment around a point is non-null, then the entire system will have a rigid-body rotational acceleration (if $M\neq0$, then $\alpha\neq0$). This happens all the time in the real world, of course, but we call those mechanisms, not structures.