In the above log screenshot it looks like the task is running for approximately 5 minutes which suggests something like PHP's max_execution_time is 300 and being exceeded.
So could the problem be that deleting courses that contain H5P activities triggers a backup which is exceeding max_execution_time and never completing?
There's a workaround for the slow H5P backups: add $CFG->mod_hvp_backup_libraries = '0' to config.php to exclude the H5P libraries from the backup, I don't know if that would adversely impact restoring the course from the recycle bin.
The raw binary output in core_course\task\course_delete_modules is concerning! Which version of mod_hvp is installed?