Let's put some numbers on it. It could simply be sagging under load, or it could be overheating. Note that the battery pack on that bike is nominally 36V. The 40V you measure is only possible open circuit (unloaded), but I've used it below anyway to make the mental arithmetic easier
560W peak at 40V is 14A. If this is sagging to 31V under load that means (Ohm's law) you've got 9/14 or about 0.7 ohms resistance between the ideal battery and where you're measuring (that seems plausible to me). The power dissipated in that resistance is 0.7x14x14 or nearly 100W. It won't take long for that to heat up an over-temperature sensor which is likely to be close to some of the heat generated. Even if we run the numbers on the 7A it delivers after sagging that's 25W - so still plenty of heat. So overheating could make it cut out quite quickly. Heat will also increase the resistance of the links between the cells, causing the voltage measured at the battery terminals to drop.
Heat generated in the battery module isn't easily got rid of; the motor controller is better able to lose heat, which it also generates, but can still get hot, especially at over twice the rated continuous current.
If the voltage drop is causing an undervoltage sensor to kick in, that would be pretty much instant when max power is applied. If a lithium cell drops below 2.8 to 3V it can suffer permanent and dangerous damage, so cells are often designed to fail completely but safely instead. Battery controllers aim to prevent individual cells getting this low, and that's probably what's cutting out in your case. You've got a 10-cell battery, so a controller saying the pack must not discharge below 3.1V is reasonable.
Battery aging can be an issue even if it is a matter of overheating, as for most battery chemistries increased internal resistance is part of aging.
So the controller is behaving as designed and protecting the battery and you. What can you do about it?
- pedal harder
- use lower assistance levels
- bring in the throttle (if present) gently as you start the steep bit
- or step up the assistance a little at a time while still pedalling at the same effort.
The 250W rated power will take you up 10% very slowly (and you may get into motor heating issues with no cooling airflow), so expect to work with it. Based on estimates of what my legs put out on climbs like that, you should probably expect little better than walking pace (you+bike+motor are lighter than me+bike, but you have to take into account motor efficiency)