You should use wp_get_post_categories() to get the categories related to a post.
Inside the loop of terms you should use
$image = get_field('main_image', $category);
What you do with that depends on what you have the return value of the image field set to https://www.advancedcustomfields.com/resources/image/