Sometimes the power button will only work when the MacBook is on or being held down and not pressed, common with minor liquid damage.
Check the trackpad board (where the keyboard plugs in) and especially both sides of the trackpad cable (gold contacts). If this is burnt or liquid damage, this is likely the issue. If this looks fine, but a new keyboard, plug it in and test it.
If the trackpad cable looks fine, trackpad board is fine and a new keyboard does not resolve the issue, will be related to the logic board so this needs to be diagnosed. My money is on the keyboard :)