That is a deep question actually.
The tldr answer is that the center of gravity of all the boxes must be over the pivot for balance. And you calculate center of gravity with the weighted sum of the individual weights.
$$ \text{(center)} = \frac{ \sum_{\rm all} \text{(position)*(weight)} }{ \sum_{\rm all} \text{(weight)} } \tag{1}$$
The term weighted sum in mathematics comes exactly from this operation in physics. The weight describes how important each position is.
But the above is kind of a circular argument, as here in the numerator we have $\text{(position)*(weight)}$ which is exactly what you are asking about. Why the multiplication.
The mathematical answer is that the above equals to the sum of each fractional contribution of position. Each fraction being the individual weight to the total weight (and thus the term weighted average).
$$ \text{(center)} = \sum_{\rm all} \text{(position)} \left( \frac{\text{(weight)}}{\text{(total weight)}} \right) \tag{2}$$
The long answer is that each force acts along a line, and when two or more forces add up together there are some rules of geometry that dictate where the resultant force acts though. You learn in high school how to add vectors by placing them on the same origin, which yields the correct magnitude and direction, but this is not sufficient to find out where the resultant acts.
So for two non-parallel forces acting through separate points, A and B as seen below the process involves 4 steps.

- Slide each force along their line of action until the forces meet at a point C.
- Combine the forces vectorially (component by component) on the common point.
- Describe the new line of action of the combined force as parallel to the combined force and through the point C.
- (optional) Slide the combined force along its line of action, back to wherever makes more sense for the problem at hand. For example on the line connecting the two original forces to new point D.
Note with force vectors you are free to slide them along their line of action without changing the problem at hand.
So what happens when the two forces are parallel? Well follow the same process as above, but the point where they meet is at infinity (on the horizon) and when you do the final step #4 the point D ends up being mathematically at the weighted sum of the two original forces.
The same argument as above can be done algebraically instead of geometrical by considering the torque about the pivot. Torque is the numerator of expression (1) and the geometry of the problem introduces the concept of a moment arm of a force. This means that only the perpendicular distance counts.
$$ \text{(torque)} = \text{(distance)} * \text{(force)} \tag{3a} $$
or in vector form
$$ \vec{\tau} = \vec{r} \times \vec{F} \tag{3b} $$
Balance happens when the sum of all the torques are zero, which has the geometric interpretation that the combined force line of action goes through the pivot.