To duplicate the problem:
Define a new role Keyholder with all permissions Not set
Set enrol_manual_keyholdername = Keyolder (Site administration -> Courses -> Enrollments -> Internal enrollment)
Assign the Keyholder Role to user X in category Miscellaneous.
Create a new course C in category Miscellaneous. Set an enrollment key. Do not assign a Teacher.
Login as student and click course C
You will get message: "This course requires an 'enrolment key' - a one-time password that you should have received from teacher"
- Why doesn't the message instruct the student to get the key from user X?
The code in enrol/manual/enrol.php (around line 378) looks like it should return user X
$contacts = get_role_users($CFG->enrol_manual_keyholder_role,get_context_instance((CONTEXT_COURSE,$course->id))