wp_get_attachment_image function size argument not working if I also add a custom class

Just as Tom mentioned in the comments above. The fourth parameter of wp_get_attachment_image sets the value, not adds to it so it will override the auto generated class.

If you need the size class and your custom class you can simply add both of them manually like so…

echo wp_get_attachment_image( $image_id, 'image-size', '', [
  'class' => 'some-class attachment-image-size size-img-size'
] );

I