I thought I had found a solution, which was to use the phone's sensors. Scanning for all the sensors on the Galaxy Z Fold 5 and the Fold 4 (using Samsung's Remote Test Lab), I identified a series of promising looking sensors:
Public const SENSOR_TYPE_HINGE_ANGLE As Int=36
Public const SENSOR_TYPE_FOLDING_ANGLE_NON_WAKEUP As Int=65686
Public const SENSOR_TYPE_lid_angle_fusion_Wakeup As Int=65695
Public const SENSOR_TYPE_folding_state_lpm_Wakeup As Int=65697
So I started monitoring them and folded/unfolded the phone.
PSHinge1.Initialize(SENSOR_TYPE_HINGE_ANGLE)
PSHinge1.StartListening("SENSOR_TYPE_HINGE_ANGLE")
PSHinge2.Initialize(SENSOR_TYPE_FOLDING_ANGLE_NON_WAKEUP)
PSHinge2.StartListening("SENSOR_TYPE_FOLDING_ANGLE_NON_WAKEUP")
PSHinge3.Initialize(SENSOR_TYPE_lid_angle_fusion_Wakeup)
PSHinge3.StartListening("SENSOR_TYPE_lid_angle_fusion_Wakeup")
PSHinge4.Initialize(SENSOR_TYPE_folding_state_lpm_Wakeup)
PSHinge4.StartListening("SENSOR_TYPE_folding_state_lpm_Wakeup")
The only sensor that fired was SENSOR_TYPE_HINGE_ANGLE and that was only on folding the phone. (It didn't fire on unfolding!)
Interestingly, the Fold 4 paused and resumed the B4A activity whenever the phone was folded and unfolded. This would be an ideal time to check to see if the screen size had changed, but the Fold 5 did not have this behaviour, the Fold 5 only paused and resumed the activity on folding. So that approach doesn't seem to be viable.