How to add edit users capability to a custom role?

In the particular case that you were working on a multisite installation. Did you try to also add the ‘manage_network_users’ capability?

function edit_shop_manager() {
    // Get custom role
    $shop_manager = get_role('shop_manager');
    $shop_manager->add_cap('create_users');
    $shop_manager->add_cap('edit_users');
    $shop_manager->add_cap('manage_network_users');
    $shop_manager->add_cap('delete_users');
    $shop_manager->add_cap('list_users');
    $shop_manager->add_cap('remove_users');
    $shop_manager->add_cap('promote_users');
}
add_action( 'init', 'edit_shop_manager' );