From your description, it sounds most likely that the battery pack is losing too much Voltage under load and causing the problem. The first step we would take is to load test the battery pack to confirm its condition. This can be done by checking the battery pack Voltage with the power switch on, and then hold the bike still and start giving it throttle and see if the battery pack Voltage gets lower. If the battery pack Voltage drops under 32 Volts during this test then the battery pack is not producing enough Voltage under load to keep the speed controller on.
Here is a link to our battery load testing guide: https://electricscooterparts.com/loadtest