The RX580 has a Fan feature called "Zero RPM" .
This feature keeps the RX580 fans turned off until it reaches a specific temperature between 55c - 60c. Once it reaches that specific GPU temperature the fans will start running.
Which version of Ubuntu to have installed? Which version of AMD Linux driver do you have installed?
It sounds like as soon as "Zero RPM" is actuated is when your PC freezes. Sounds like a Linux AMD driver issue.
One way to eliminate Linux AMD driver is by temporarily installing your RX580 in a Windows PC and see if the same thing occurs. If it does then you most likely have a defective GPU card but if it doesn't and the fan works normally than it is your Linux AMD driver which is the problem.
Zero RPM can be overridden by AMD Radeon settings or some other Fan controller program using Fan Profiles.