We used to temporarily block access to courses while keeping data by setting the course-status of the user to "suspended". As I understand it, the user should not have access to the course while suspended. There is only manual enrolment and no guest access to these courses.
Today I realized, that users who are suspended in a course still have access to that course. This is the case all over the whole platform.
I never tested this before today, as I am not the only admin and was never confronted with this aspect, so I don't know if it ever worked on this moodle instance, but I suppose it would have shown up earlier if it had never worked.
We are now on Moodle 3.5 branch
Edit: When setting the status to "suspended" the role "student" does not get removed. Only when setting the status to "suspended" AND manually removing the role of "student" the access to the course is blocked. That results in data being kept and having the student without any role listed in the course.
role:student + suspended = accessible
no role + active = accessible
no role + suspended = blocked