The mechs that have been developed are 40 tons and 5 meters tall at the smallest and can reach to 250 tons and 25 meters tall at the biggest. They are mostly capable of carrying large weapon systems and are somewhat manuverable, depending on the chassis and the skill of the pilot. Would they be able to replace the traditional frontline infantry soldier in all the duties that they carry out? This includes fighting against opposing forces of a similar tech level as well as fighting smaller fighting forces. If not, what sort of roles could the mechs never fill and what would they best be suited to?
Infantry and armor are separate divisions for a reason. A tank or a mech would never be able to effectively capture an objective unless it is sitting in the middle of a plain with strong surface. In cities, forests, deserts, shores, etc. the mobility provided by infantry cannot be replaced by the size, armor and firepower of mechs. Current trends in warfare eschew frontal conflicts in favor of asymmetrical warfare (Middle-East) and covert operations (Ukraine), in these situations mechs would mostly just be dead weight.
They could however serve as mobile HQs, carrying supplies, officers, comm gear and other stuff that is good to have sometimes. This way the reduced speed (compared to wheeled, tracked or flying units) and the reduced mobility (compared to infantry) does not pose a problem, and the heavy firepower could come handy in case of an assault. The huge carrying capacity (What else would fill 250 tons, if the Battletech mechs max out at 135, and even they can lay waste to entire cities? Certainly no more weapons are required.) could be useful for repair facilities, medical bays, etc.
This proposition would essentially turn mechs into walking bases, and in this view it would make sense to have a mobile (transport) and a stationary configuration, with the former offering the legs less protection but more mobility, and the latter anchoring the mech to the ground, sliding armor plates over the vulnerable leg joints and extending the big guns and sensors on arms, therefore making aiming and target acquisition easier. For references see the Transformers Trypticon and Metroplex, both have an "assault base" configuration.