Can't be done exactly like this afaik, but you could do something that has essentially the same effect.
You can have units with no model that have the same abilities as a town hall. That way units will actually bring resources to this invisible unit, but if you place it on an existing building it looks like they're using that one.
What makes it complicated is that you would have to add and remove those units when town halls are created or destroyed.