WP Rocket tries to delete the entire cache folder in a single request. When the folder contains millions of files the file system operations take longer than the PHP and FastCGI timeout limits.
The server aborts the request after about 120 seconds. The admin UI shows a 502 or 504 error and the cache remains partially cleared.