Vide moodle\enrol\cohort\edit_form.php, ~ line 85.
One of the controls in the form is for selecting the role to assign. When the form is editing an existing enrolment instance record, but the roleid in that record is not one of the choices for role as determined by the prior call of get_assignable_roles(), the intent of the following code is to append another choice.
However, this block of code happens after the choices have already been provided to the selection control. Therefore, the block of code has no effect.
If this block of code is still relevant, I suggest that it be moved to before the call of $mform->addElement(). For example: