Hi there!
Likewise, as @James Brickley had mentioned, resetting the SMC is a good and simple step to a fix for power related issues!
If that we’re to not fix the problem:
You can run a hardware diagnostic on your Mac yourself by following these steps:
https://support.apple.com/en-us/HT202731
Another way to check your battery cycle count (A Mac has an estimated battery cycle count depending on the model, for example 1,000) is by checking the System Information:
https://support.apple.com/en-us/HT201585
Otherwise, can you say if the same occurs with another cable or charger? Or even when connected to another outlet? If so there are more isolation steps to take, but hopefully the good old SMC zap will fix it!