What is the working principle of trim tabs on the elevators?
The trim tab is like a control surface for the control surface. By changing camber at the rear end of the control surface, it creates a local force which changes the balance of forces such that the force-free deflection angle (sometimes called auswehwinkel after the German word for this angle) is shifted in a direction opposite to the deflection of the tab.

You could do the same with springs along the control rods, or a mass somewhere which pulls the control surface to the same force-free angle. But when speed changes, so do the aerodynamic forces, and your force-free angle will change. The forces caused by the tab change with airspeed, so the force-free angle set by a tab is unaffected by speed.

Don't confuse a trim tab with a Flettner tab: The trim tab stays at the same angle with varying control deflection, while the Flettner tab will move in opposite direction to reduce the stick forces caused by the deflection of the control surface. By setting the zero-deflection position of a Flettner tab, it can in parallel work like a trim tab and shift the zero-force deflection angle to the desired point.

Small aircraft like the Diamond Katana even have an anti-Flettner, where the tab is moving in the same direction as the control surface in order to increase stick forces. This is needed to fulfill certification requirements.

In practice, a combination of both springs and tabs is used to set the desired control forces and their gradient over speed.