So there was an issue when user couldn't delete course when repository is deleted - Moodle threw error that repositoryid is not found. There is a patch https://tracker.moodle.org/browse/MDL-51871, but it only affects courses where repository was deleted after applying a patch. When you delete a repository, this patch deletes all files asscoated with it. But if repository was deleted before patch then there is still same issue when deteing a course - it tries to create a backup and put it to rubbish bin and it can't find repository.
So to sum up assuming you haven't applied patch:
This workflow is fine:
1. Create course with some files using repository
2. Apply patch
3. Disable repository
4. Delete a course
This workflow is failing:
1. Create course with some files using repository
2. Disable repository
3. Apply patch
4. Delete a course
Is there a workaround for that?