SEOmatic: Change type of mainEntity
So you can't just change the type of the mainEntityOfPage because there's a unique PHP class for each schema.org type.
What I would typically recommend here is that you set up the mappings via Content SEO (which lets you set up a different mainEntityOfPage per entry type) or you use the SEO Settings field to allow for per-entry changing of the mainEntityOfPage.
But if you really want to do it dynamically via Twig, you can. You just need to create a new object.
{% do seomatic.jsonLd.create({
    'key': 'mainEntityOfPage',
    'type': 'Whatever',
{# fill in other properties here #}
}) %}