Getting featured image with direct $wpdb within plugin

That is not how you would query for a featured image. This:

$thumb = $wpdb->get_var("SELECT ID FROM $wpdb->posts where post_parent="$value" and post_type="attachment"");

Should be:

$thumb = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta where meta_key = '_thumbnail_id' and post_id = '$value'");

That is assuming that $value is a post ID.

“Featured” images are attachments, but not all attachments are featured images. That is why this works sometimes but not others.

However, you’ve just reinvented the wheel. What you are doing is exactly what get_post_thumbnail_id does, though that function uses proper Core mechanisms.