It could be a loss of connection. I have seen an ebike bottle battery that broke internally and caused the same problem whenever the connection was lost.
Check that the brake lever isn't cutting off power to the controller, or any loose connectors. When does this happen? If when you hit a bump in the road, or anything else.