It is called Archimedes principle
Principles in physics are a part of the extra axioms needed in order to be able to model with mathematics physical observations, in this case the way the water (or fluid) is being displaced by the addition of an object in a bath of water.
A principle is the result of observing a physical phenomenon and finding out that a specific statement applies for all similar cases. At the time it was established as true, that it always worked , it helped in the progress we have made to the physics model we use now, where why this happens can be explained with more elaborate theories and different axiomatic assumptions.that make up the theory of thermodynamics, the concept of buoyancy.
We now describe matter in terms of temperature, volume pressure, density ... and the axioms of thermodynamics are far removed from Archimedes principle, but it still holds because it depends on the observations of matter.

Buoyancy arises from the fact that fluid pressure increases with depth and from the fact that the increased pressure is exerted in all directions (Pascal's principle) so that there is an unbalanced upward force on the bottom of a submerged object.
you ask:
Shouldn't the mass of water displaced be equal to half the mass of the rectangle, the part inside the water? Why is also the amount of mass outside of the water being displaced?
It is a matter of density, grams per centimeter cubed. For the object to float it has smaller density than water, otherwise if the density were the same to water it would float below the surface or move anyplace in the bath, if larger, it would go to the bottom.