Haven’t tested this but I’d look at your loop where you’re going through the user IDs. The first $output declaration is just:
$output = '<div class="bp-user-profile">';
Which would be fine if it was a single loop through it but every subsequent loop I think would get messed up by this, so the returned ID is maybe the last one in your field? It may be as simple as changing it to:
$output .= '<div class="bp-user-profile">';