Hello Manojgonugunta,
With this only happening after connecting your charging cable, it could be related to the cable. Do you have a different charging cable that you could use to test? Just in case, here's more information on the message you're seeing: If your Mac restarted because of a problem - Apple Support
We can also narrow this down to possibly being related to the software by testing this issue while started to safe mode. Safe mode keeps certain software from loading and other great checks during startup that can help to isolate this. Here's a guide with more information about safe mode, and how to start there: How to use safe mode on your Mac - Apple Support
You'll follow the additional guidance for if the issue does or does not continue in safe mode:
If the issue continues in safe mode
If the issue continues while in safe mode, or your Mac restarts several times and then shuts down while starting up in safe mode, you should reinstall macOS and make sure that your Apple software and third-party apps are up to date.
If the issue doesn't continue in safe mode
If the issue doesn't continue while in safe mode, leave safe mode by restarting your Mac normally. Then test for the issue again. The issue might be resolved.
If the issue returns after leaving safe mode, startup items are probably at fault. Apps can install such items in numerous places, and they aren't always easy to find or recognize. For that reason, you should first make sure that you've installed any available updates for your Apple software and third-party apps.
If updating your software doesn't help, try any of these solutions:
• Test your login items.
• To learn whether software in your user account is causing the issue, set up a new user account, then log in to it and try to reproduce the issue in that account.
• Unplug all accessories from your Mac, including printers, drives, USB hubs, and other nonessential devices. You could have an issue with one or more of those devices or their cables.
Reinstall macOS.
Keep us posted on the results.
Take care!