Random 404 errors using Buddypress

To answer your question, if you are not using the LearnDash plugin then you should not add the code that is in the accepted answer of the link you have there.

That code essentially is adding a filter named learndash_flush_rewrite_rules which appears to be specific to that plugin. If you don’t have it enabled, it will most likely never run.

I took a look on some tickets and found this BP ticket which may get you started with a different solution.

One person had their issue fixed adding the following to functions.php:

add_action('delete_option_rewrite_rules', function($option){
   global $wp_rewrite;
   $wp_rewrite->use_verbose_page_rules = true;
}, 10);

Definitely test that on a non-prod server before using, not sure why it worked for them, and it was 6 years ago.

Lastly, this is definitely a difficult error to troubleshoot. I’d recommend that you start debugging by logging all your 404 errors and perhaps try to recreate the bug while debugging is turned on. An idea to not disrupt production might be to have a bunch of puppeteer scripts all going to a staging version of your site and log the errors that way.