A large machinegun would likely put it out of action with leg hits.
I'm struggling to think of ways you could effectively armor a leg-joint such that it would withstand assault rifle fire. You shouldn't even need a heavy machinegun, and IED's are going to put them out of commission for sure.
Yes, it would be nice if the Japs would stop beating the mecha horse to death and actually introduce proper military units like tanks.
Off the top of my head, I can only think of one semi-reasonable mecha anime and that's Blue Gender where the mechs are simply upscaled versions of powered armour, 3-4 metres tall.
I don't know it's name, but there is at least one series where the mechs don't go any further than about 2.5 meters high. Some anime (even some of the gundamns, iirc) do feature tanks that are highly effective in combat.
But it really is a pervading trope that comes nearly exclusively from Japan.
As an additional note, there is an obvious niche where humanoid robots have the potential to be highly effective, and that is in the same role regular infantry are in today. Powered armor is the simplest form of this, but remote-piloted robots the same size as a human will give you the ability to traverse buildings and ride in vehicles like normal infantry.
The obvious advantages are heavier load-bearing capacity, the fact that when it gets blown up, and you don't lose an experienced solider (and can redeploy the soldier to the field as soon as a replacement robot is shipped). Increased load-bearing implies heavier armor, as well as more potent weapons with more ammunition for them.
The obvious disadvantage is that they will inevitably be highly expensive (although perhaps not considerably more expensive than powered armor, since it is essentially PA without a pilot taking up space inside it), and that even with thicker armor, it will still get mobility-killed by shots to knee joints and the such, and it's not really plausible to armor such a robot against grenades or explosives.
That said, facing down an army of robots that you can never really kill that are inflicting disproportionate casualties on your own forces has got to be bad for morale
Generally speaking, a good rule-of-thumb for determining whether a humanoid robot would be militarily useful is whether it can fit inside buildings or not. If it can (<2 meters high), then it can take cover in buildings, traverse them, and so on. If it can't, then it's forced to be outside all the time, and is unable to take advantage of most cover (which is generally shorter than an average human).
So if they can go inside buildings, they face down infantry, who they can be reasonably expected to triumph against in many cases, but if they're forced out-doors, then they're forced to face down tanks and IFV's, which are armed with 20mm cannons on the low-end, and will thus completely obliterate you.