I think there are other categorical ways to model substitution, but this is pretty cool.
T builds terms from variables.
Terms over terms over variables become terms over variables. From there, it's easy to go to the Eilenberg-Moore construction of an adjunction from a monad. For example, for the term monad, we could take A to be natural numbers and evaluate terms. The free algebra is initial in the category of T-algebras. The unit of the adjunction is the monad unit.