When you upload an image to WordPress, the website makes an attachment page. WordPress Attachment Pages are another post type. You might have noticed this when you add an image that you have the option to link it to an attachment page. For most business websites this is not particularly helpful, it can hurt your SEO. Google indexes those pages.
You can fix the WordPress Attachment Page Issue with the Yoast Plugin
If you haven’t done this already, turn on the Yoast advanced settings.
Then go to
SEO> Advanced >Permalinks
You need to turn on the redirect on the Yoast settings. The media attachment page is redirected back to the post in which the image was added (when you uploaded it).
When I uploaded an image from within this post, the image is attached to this post. Consequently, with redirect turned on, the attachment pages will redirect to this post.
That makes sense. When you search for an image in “google image search” and click to the page, the site will direct you to the post or page the image was used on rather than an attachment page.
It is also helpful for SEO. The redirection prevents the indexing of all those attachment pages. Even if you have added a title and a description and alt text to the image, chances are, you probably haven’t filled in a meta description or focus keyword for all those images. The exception perhaps would be if you are an art gallery or photography site. In which case, you will want to improve the existing WordPress Media Attachment template and not do the redirect.
There is another option to code it, which you can read over at Media Attachment Pages who needs ’em right?