$length expression function states that
The length calculated by this function respects both the current
project's ellipsoid setting and distance unit settings. For example,
if an ellipsoid has been set for the project then the calculated
length will be ellipsoidal, and if no ellipsoid is set then the
calculated length will be planimetric.
QgsGeometry.length on the other hand says
Returns the length of geometry using GEOS
Sadly this is not very helpful if you don't know what GEOS means. GEOS is the underlying geometry engine and it has no idea about coordinate systems, ellipsoids and all that spatial stuff. It is purely about geometry. This means
QgsGeometry.length will consider all coordinate values of the geometry as flat cartesian coordinates. You might know they are geographic/ellipsoidal, GEOS does not.
If you are in a length-preserving projection with meaningful units (meters), the result will (almost) be the measurement as if done in the real world. But in all other cases, the results from this function are rather useless.