Shutdown prompt keeps popping up
It might your keyboard issue which is just a random guess. However before going on hardware, why not you try to reset SMC. 

The System Management Controller — or SMC — is responsible for various pieces of hardware inside your machines such as the battery, fans, logic board and more. 


The SMC is even responsible for recognizing when certain buttons are
pressed.


You can take the guidance from https://support.apple.com/en-us/HT201295

It doesn't hamper anything so I think it is worth to try.