Each troop has a specific troop type that counters it. Think of it like Rock-Paper-Scissors. Range troops beat Mounted; Mounted beats Ground; and Ground beats Archers. The exception is that Siege beats all except for siege that has longer range.
These counters are not hard coded into the but come from natural stat differences in battle. First example would be why Archers beat Cavs; Archers range gives them several rounds to fire before the Cavs even get near them. Couple this with the generally lacking HP and Defense of the Cavs and they tend to fall pretty fast from Archer fire. This counter can be countered by Buffing your Cav's HP as high as possible while debuffing your enemies Archer's Attack.
Cavs beat Ground because although Ground have the highest HP and Defense stats of the troop types; Cavs have the Highest Attack and tend to be able to one-shot all but the beefiest Ground Troops thus neutralizing their normal ability to take multiple rounds of Archer and Siege fire. If you can get your Ground Troops to have high enough HP and Defense they can tank just about any hit. If you are running a lot of Ground its a good idea to be building with Cav Attack Debuffs
Ground beats Archers due to their aforementioned high HP and Defense; Allowing them to tank the several free rounds of shots the Archers get off and crash into the low HP and Defense Archers. Its really hard to beat Ground with Archers as you would need to buff the hell out of your Archer's Attack while Debuffing the hell out of your Enemy's Ground HP and Defense. Not entirely impossible but it would take an exuberant amount of for you Sub City Generals.