I fail to see why that doesn’t work actually but still…
So you could try this direct database query which does the same thing as the code version but does less work:
UPDATE wp_sfforums SET
post_count = (SELECT COUNT(post_id) FROM wp_sfposts WHERE forum_id = XXX),
topic_count = (SELECT COUNT(topic_id) FROM wp_sftopics WHERE forum_id = XXX)
WHERE forum_id = XXX;
usual rules. Table prefix… Change XXX for the forum ID you need to check and update (i.e., the one where topics were manually removed from). And make that usual backup!