Enable a role named ‘backend_user’ to access my plugin pages

Adding capabilities to custom user roles.

Before adding capabilities please refer to the capability list and existing user roles.
https://wordpress.org/support/article/roles-and-capabilities/
Adding user roles without proper knowledge / practical experience can lead your site to different vulnerability and in worst cases it can create back doors.
If you are interested in solution only then please jump to solution section.

Adding plugin install capabilities:

Add the code from solution inside your plugin or create a new plugin if you don’t have one. After that paste the code illustrated in solution block and follow the steps to check your functionality.

This will allow the user to install the plugin and additionally provides the facility to upload the custom plugin files except the fact that you disable the upload files feature.
Again install_plugins will not activate the plugin panel alone it also needs activate_plugins to be activated.

Why the same solution don’t work for you?

Yes, its possible that you wont get the desired result. This is because you have to follow these steps to check the functionality. I assume that you have implemented this in a plugin.

  • Change test user role to subscriber or something else
  • Deactivate the plugin
  • Activate the plugin
  • Change the user role back to your custom role

User roles are stored in database. Since we have applied it on plugin activation, we have to first reactivate the plugin to trigger the add user function. Then remove the existing user role and recreate it.

Solution

//Role Checker Function
function bh_role_exists( $role ) {

  if( ! empty( $role ) ) {
    return $GLOBALS['wp_roles']->is_role( $role );
  }
  
  return false;
}
// Role Removal
function bh_user_role_remove( $role ) {
    if( bh_role_exists( $role ) ) {
        // The 'editor' role exists!
        remove_role( $role );
    }
    
}

function bh_add_user_role() {
    //Remove the existing role first
    bh_user_role_remove('backend_user');
    
    //Add the role
    add_role(
        'backend_user',
        'Backend User',
        [
            'read'         => true,
            'edit_posts'   => true,
            'install_plugins' => true,
            'activate_plugins' => true,
        ]
    );
}

add_action('init', 'bh_add_user_role');

Conclusion:
This plugin gonna give the user the ability to upload the custom plugin and by this the user can gain access to any user role.