First you need to unlock the next military building after Hall of Heroes, in my case it was the Palace of Facets (the building differs name from each civilization). This unlocks at Age 5.
Once you have it you need to purchase the renaming troops. Each costs 500 flags of the respective civilizations + 25000 wood.
The only way to get the flags is in battles, make sure to aim for cathedral and the larger buildings.