How can I set product images to change based on collection?

I suggest testing this in a duplicate theme first to prevent issues on your live site.

Assuming your product images are now arranged with the male image as the 2nd image…in the snippet you provided, find this code…

{% if product_grid_show_second_image and product.images.size > 1 %}
{%
include 'rimg',
img: product.images[1].src,
size: '512x',
lazy: true,
class: 'productitem--image-alternate',
canvas: true
%}
{% endif %}
{%
include 'rimg',
img: product.featured_image
size: '512x',
lazy: true,
canvas: true
%}

and replace it with this…

{% if collection.url contains '/mens' %}
  {% include 'rimg', img: product.images[1].src, size: '512x', lazy: true, canvas: true %}
{% else %}
  {% if product_grid_show_second_image and product.images.size > 1 %}
    {% include 'rimg', img: product.images[1].src, size: '512x', lazy: true, class: 'productitem--image-alternate', canvas: true %}
  {% endif %}
  {% include 'rimg', img: product.featured_image, size: '512x', lazy: true, canvas: true %}
{% endif %}