Provided as is, backup beforehand if in doubt..
MySQL query
DELETE c
FROM wp_posts p
LEFT JOIN wp_comments c ON c.comment_post_ID = p.ID
WHERE p.comment_count > 0
AND p.comment_status = 'closed'
Using WordPress wpdb class
$r = $wpdb->get_results( "DELETE c
FROM $wpdb->posts p
LEFT JOIN $wpdb->comments c ON c.comment_post_ID = p.ID
WHERE p.comment_count > 0
AND p.comment_status = 'closed'");
Queries the posts table for posts with a comment count more then 0(it's the last column of the posts table), joins the comments table matching against the post's ID and deletes the matching comments.
Only tested very briefly on a local installation(2.9.2), so i can't say for sure if it's perfect, so use at your own risk.
NOTE: My testing was done in PHPMYADMIN, so i'm not sure if the wpdb method above is correct, but it's there simply to show how it might look inside a wpdb method..