Solution:
If you check for the image ID with parameter $context=”edit”, you will only get a returned ID if the image is set directly to the variation. The code looks like this:
$image_id = $variation->get_image_id('edit');
if ($image_id){
//Only if there is an image to the variation itself
echo $image_id;
}
Ref: https://docs.woocommerce.com/wc-apidocs/source-class-WC_Product.html#662-671