Hide tab Buddypress profile for visitors, not logged in users

I think the function you are looking for is bp_displayed_user_id(). That will get the ID of the user whose profile is currently being displayed.

Then, you can check their role like this:

$user = get_userdata( bp_displayed_user_id() );
if ( ! in_array( 'subscriber', (array) $user->roles ) ) {
    return;
} 

You could also use user_can(), but it is best to avoid using role names with user_can() and current_user_can(), as they are really designed for capabilities and not roles. In fact, you ideally would not check user roles in a case like this at all. It would be better to add a custom capability to certain roles, like 'extended_bp_profile', and then check for that instead.