I’ve recently had this problem on a few projects. The cause seems to be some WooCommerce payment gateway plugin that regenerates its endpoints on each query and force flush rewrite rules.
As says:
So, you can safely disable write of .htacces
file adding the filter:
add_filter('flush_rewrite_rules_hard','__return_false');