On legacy, it is possible to limit the number of content versions that are created through settings ("DefaultVersionHistoryLimit", "VersionHistoryClass"). On the Public API, no such mechanism exists, and users are free to create as many content versions as they like, either accidentally or by design. At some point, it might be necessary to cleanup all that clutter from the database, and the cleanupversions.php script has been created with that task in mind.
However, since there is not a content version limit in the Public API, a single content can have many versions, potentially tens of thousands of versions or even more.
The cleanupversions.php script just isn't robust enough to deal with this amount of clutter, it simply hasn't been designed to deal with such big cleanups. Please create an alternative script capable of cleaning up large amounts of content versions, in a reasonable amount of time.