You might find a way to use the Moosh utility that allows programmatic unenrolment
Unerol user(s) from a course id provided. First argument is a course ID then list of users.
Example 1: Unenrol users with id 7, 9, 12 and 16 from course with id 2.
moosh course-unenrol 2 7 9 12 16