How to update permalink programmatically?

flush_rewrite_rules should only be called on the plugin activation OR after you update or add rewrite rules programatically.

If it does not work after verifying this, there is some other issue on your site. Make sure you are not calling flush_rewrite_rules in constructor or somewhere else on every page load.