That's your problem right there: with speed sensor unplugged, the ECU thinks that you are idling and turns engine off after 20 minutes.
You may want to plug the speed sensor back in; the signal may be erratic, but it may be enough for the ECU to register the bike as moving and not impose the 20-minute shut-off rule of an idling engine.