Automatically apply tag to folder based on content
The proper tool for this job is Hazel.
It can apply tags based on file names, file extensions, even file contents and a lot more. It can also do that on sub-folders as well.
The app has been around for a long time, its developer is very well respected, and the app is well worth its asking price.
There’s a free trial available which you should download and try before buying, but it’s an essential tool for me, and much easier to deal with than Automator and Folder Actions.
Updated To Add
I’m 99% sure that Hazel can do this (if I am understanding the idea properly), and would recommend checking out this page as a starting point:
https://www.noodlesoft.com/manual/hazel/advanced-topics/processing-subfolders/
The developer is also very responsive. The best place to ask questions is here:
https://www.noodlesoft.com/forums/