Without the full list of hardware it’s a guessing game, but my best guess is that you’re using a first or second gen ryzen and did not set it up with the recommended bios settings, which are:
Disable erp-ready, global c-states and amd cool & quiet on older bios versions and on newer bios version setting power supply idle control to typical idle current from low idle current.
With first and second gen ryzen there’s a bug that cuts power to certain components when the cpu is mostly idle and it fails to wake them up again, which leads to the freezing.