How to dynamically add template in Innerblock?

That’s not how templates work.

A template is the initial block layout, a starting point.

Changing the template won’t do anything because the original template was used to create blocks and those blocks have already been created. Think about it, if it worked the way you thought it did, adding or removing from the template would erase all the content, and your content would be erased when the post loads.

What you’ve done is attempted to create a custom block appender, so instead of reinventing that feature you should instead use the block appender props and APIs. Templates are not appropriate for what you’re trying to do.

TLDR: If you want a custom block appender/inserter, use a custom block inserter/appender, don’t try to make templates dynamic, they aren’t and can’t be made dynamic, that’s not how templates work.