I’m assuming you’ve fixed this by now, but I had the same issues, symptoms, and had tried many of the same solutions. After a bit of digging I was able to find a solution through an easy database fix and wanted to share for anyone else who might reference this post.
In your WP DB find the wp_options table. In this table look under the option_name for home. The value should be your website base URL, https://www.example.com. Change this value to https://www.example.com/sub-directoy and commit the change. Now you should be able to switch permalink structures back and forth without errors.
To hide the WP install directory from being displayed in the URL change the value for home back to your base URL, https://www.example.com. You should still be able to switch permalinks structures without issues. For me, this seemed to overcome the gremlin was at work in my DB. YMMV.