Drop in desired altitude when changing to RTL

Firmware version: 4.2.2 with some modifications (none that should affect mode changes)

The drone was executing an AUTO mission with RangeFinder based Surface Tracking and, when mode changed to RTL, the altitude set point changed from around 3.5m to 2m. The drone complied and dropped about 1.2m before starting to climb. I had a look in the mode change code for RTL and I believe that this drop shouldn’t be possible. I want to understand what caused the drop in Desired Altitude and how to make sure it never happens.

Flight Log