Students or participants in a Moodle course room can deregister themselves (except for centrally created e-exam courses).
In the course room, select the tab “More” and then click on “Unenrol me from …”.
Video: Removing yourself as a participant from a Moodle course.