Bad power supply, practically guaranteed. The logic board capacitor may be bulging, but that won't make the unit turn itself off, so it isn't relevant to your issue at hand.
Well documented, well known issue with these units.
MacBook Pro (15-inch, Mid 2012) 2.3 GHz Core i7, 16GB, 256GB M4 SSD
iPhone 8 - 64GB S/G • Sound System Audio Engine A2 • Display UltraSharp U2412M 24"
Custom Built Gaming PC Kaby Lake Edition | 16GB DDR4 | GTX 1070 8G