Ubuntu 20.04 - Shutdown after Overheating

A full diagnosis of Hardware+Software system is hard to perform via askubuntu in your case. Hardware issues are particularly difficult.

An alternative for a first step in the diagnosis may be provided by installing another OS side-by-side with your Ubuntu 20.04, and performing intensive testing as well.

You could run the same Python program (if you can configure it to use all cores). Even so, it might not be running under the exact same condition you see shutdowns. There are quite a few applications for testing performance out there, and they should be good enough (or even more stringent than your program). And it would not have any "contamination" from your possible Ubuntu 20.04 configuration.

Later on, when the full diagnosis is finished, you can get rid of this OS and reclaim the space for your Ubuntu.