Return instead of echo

Look at bp_group_request_user_avatar_thumb() in this file /bp-groups/bp-groups-template.php.

It has a filter hook.

In your filter function, add the $html parameter and set it to false and it should return just an url to the avatar. Then you can wrap it in a href and img tag manually.

Or you could write a call directly to bp_core_fetch_avatar.

Take a look at this function bp_core_fetch_avatar in /bp-core/bp-core-avatars.php.