When destroying a project, Redmine recursively destroys all related objects.
In this case however, it tries to first destroy the (project-local) time entry activities before it destroys the time entries using those activities. Since destroying an activity is only possible when there are no time entries using it, the project destroy may fail in this case.
I believe this may be solved by making sure that during a project destroy, Redmine first destroys the time entries and only then the activities.
I haven't yet fully tested it, but this issue might be solved with a patch like this where we move the declaration of the related time_entry_activities below the declaration of the time_entries:
Subject changed from Cannot delete project (raise "Cannot delete enumeration") to "Cannot delete enumeration" error may occur when attempting to delete a project with time entries