getting post thumbnail within loop causes an error

The get_the_post_thumbnail() internally uses the global $post to get the post ID. That is why the code works while you are getting errors. it’s not required to pass the post ID to this function, so you can pass null to it.

But the error is because there is no defined $post_ID variable. If you want to get the post’s ID, you should either use global $post; $post->ID;, or better use get_the_ID().