There are two contrib modules which will do that for you:
Role Delegation
This module allows site administrators to grant specific roles the authority to assign selected roles to users, without them needing the administer permissions permission.
RoleAssign
RoleAssign specifically allows site administrators to further delegate the task of managing user's roles while withholding the Administer permissions permission.
The former is somewhat more configurable, and has the added benefit of a stable release.
If neither of those do what you're looking for, it's pretty easy to alter the user form manually. Here's a very contrived example:
function MYMODULE_form_user_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
if ($some_condition) {
$form['account']['roles']['#options'] = [
'foo' => 'Foo role',
'bar' => 'Bar role',
];
}
}