Conditionally assign a custom role on user registration
You need to use hook_user_presave. like below,

function mymodule_user_presave(&amp;$edit, $account, $category) {
  if ($account-&gt;is_new) {
    $roles = user_roles(TRUE);
    $rid = array_search('Test', $roles);
    if ($rid != FALSE) {
      $edit['roles'][$rid] = 1;
    }
  }
}


Replace the Test with your role name. $account->is_new will be set to 1 during the registration process alone, so your code will not execute when a user updates the profile.