Did you read: https://docs.moodle.org/31/en/Unenrolment#Bulk_unenrolment ? Where you can select many users at a time and unenrol them.
Courses and course formats
How to suspend hunderds of students at once?
This discussion has been locked so you can no longer reply to it.