Comment Approve – Add custom function when comment is approved

Sadly there are no hooks or filters that you could use in edit-comments.php. You’d have to build your own admin page with a custom button and use wp_set_comment_status( $comment, 'approve' ); to approve comment and do whatever you need to do…

EDIT:
I was wrong – there’s the wp_set_comment_status action inside wp_set_comment_status function https://wpseek.com/function/wp_set_comment_status/

do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status );

So you can just do:

add_action('wp_set_comment_status','average_rating',10,2);

and add to your function

function average_rating($comment_id, $comment_status) {
   if ($comment_status == 'approve') {
      .....rest of your code