Freezes after certain time when screen locked

Similar (but more severe) symptoms here:

If you have an AMD CPU, do you have the AMD Microcode installed?
sudo apt install amd64-microcode

If you have an Intel CPU, do you have the Intel Microcode installed?
sudo apt install intel-microcode

Do you have the latest AMD drivers installed for your GPU?

Other people having similar issues have tracked it down to the CPU entering a c-state so high that it dumps the GPU off the bus... AMD appears to glitch on c-state 6, Intel appears to glitch on c-state 10, which either completely freezes the system or allows the system to remain operational but the screen is blank. You might try limiting your CPU c-state:
intel_idle.max_cstate=1

I'm unsure if that works only for Intel CPUs, or also for AMD. If that doesn't work, try 0 (which keeps your CPU from entering any sleep states). If it does work, iterate through the c-states one at a time until the behavior repeats, then back off by one.

If you have an AMD CPU, try adding this to your kernel command line:
amd_pstate=passive
That'll give fine-grained, continuous frequency ranges for the CPU, rather than the standard 3 p-states, if your BIOS, CPU and kernel are set up for it.