the advantages a mech has over a tank or infantry field gun is largely in terms of height and cross-terrain mobility.. being two levels tall an urbanmech can see over small buildings that would otherwise block line of sight for a tank or fieldgun, and in doing so it also can benefit from partial cover making it harder to kill while it fires. a tank or field gun with LOS is going to be exposed for the most part. (the exception being field gun platoons stationed inside a building.. but that take a lot of time to set up
a mech also benefits from being able to more easily pass through terrain.. a mech passing through rubble/rough ground, woods, or waterways is just slowed down a little. but for a vehicle those could all stop them entirely, depending on type of vehicle. and would hinder or stop infantry field guns as well.
a mech has an advantage over field guns too in that it can fire while moving.. something that field guns cannot due to the need to set up guns for firing, and break them down for transport. (a vehicle can fire on the move, but then we get back to the "can;t cross terrain as easily" issue)
if combat makes its way into the city, having mechs on hand to provide heavy mobile and tall firepower to the vehicles and infantry is useful. but few nations will want to devote important resources to a medium, heavy, or assault class urban specialist mech. so fitting as much of that firepower and armor onto a light mech makes sense in that regard.