False Positive on has_post_thumbnail

I have tested on my test site the exact code you have shared above but it is working fine for me without any issue.

It seems you are facing the issue as described on this page WordPress has_post_thumbnail() not working – How to fix the phantom featured image issue that you might encounter, especially if you’re working with migrated content, or for some reason your database has weirdness.

So instead of has_post_thumbnail() you can use code like following to check existence of thumbnail attached to post.

$img_url = wp_get_attachment_url( get_post_thumbnail_id() );

if  ( ! empty( $img_url ) ) {

 // Do what you want to do if featured image is set to post
}