How to redirect (301) trashed post to it’s parent taxonomy TERM ARCHIVE instead of 404 page

Try something like

$post_id = url_to_postid($_SERVER['REQUEST_URI']);

Might need some tweaking: might need 'HTTP_REFERER' instead of 'REQUEST_URI'; might need to append the protocol and the domain to the string passed to url_to_postid().