Hierarchical taxonomies in permalink cause 404 for sub term archive

I’ve not reviewed your code, just a quick thought:

Have you tried Going to Settings => Permalinks and just clicking ‘Save Changes‘? That flushes the rewrite cache.