Getting “too many redirects” when using wp_redirect for attachment page

Considering WordPress Codex, and WordPress Template Hierarchy – attachments stores as post records.

Your code is making a loop redirection to the same page. The most reasonable case is:

Your $post->post_parent equal to 0. If you’ll make a var_dump(get_permalink($post->post_parent));, youll notice that the output would be the same page url.