You have to think that your flap is a small wing by it's own. The fixation point of this wing, through which all loads must be transferred is at the leading edge. Then there is a moment created at this hinge by both the aerodynamic lift and the aerodynamic moment if your profile is not symmetrical. You can calculate this moment by calculating the lift $L_f$ and aerodynamic moment $M_{0_f}$ at the aerodynamic center and then adding them after multiplying the lift by it's lever arm which is one quarter of the flap chord $c_f$. For a unit length of flap you get the following :
$$ M_h = L_{f}*\frac{1}{4}c_{f} + M_{0_{f}} =\frac{1}{2} \rho c_{f} C_L{_\alpha} (\alpha +\delta) V_\infty^2 * \frac{1}{4}c_{f} + \frac{1}{2} \rho c_{f} C_{m_0}V_\infty^2 $$
For the second part of your answer, the first diagram is showing the moment exerted on the flap to keep it down while the second one is showing the moment applied by the flap on the wing. Newton's third law gives you everything else.