not outputting medium size image URL

Just use the the_post_thumbnail() function. It creates the image tag, adds srcset for you, and supports native lazy loading:

the_post_thumbnail( 'medium', [ 'class' => 'productimage' ] );