Short answer. An eBike motor that cuts out under load is usually caused by battery voltage sag from aged cells, a loose battery contact, controller heat derating, or a failing brake cutoff switch falsely triggering.
Step by step
Test at low PAS on flat ground. If the motor only cuts out on hills or PAS 5, suspect battery sag. If it cuts on flat ground at PAS 1, suspect the brake cutoff or a wiring fault.
Wiggle the battery in the mount. A slightly loose battery causes momentary disconnects that look like motor cutouts. Clean contacts and check the latch.
Squeeze each brake lever and watch the display. If the display shows the brake indicator when you are not squeezing, the cutoff switch is stuck or the wiring is shorted.
Get a load test on the battery. A load test gives you the actual voltage under a real 15 to 20 amp draw. Sag below 3.0V per cell means the pack is dying.