This analogy assumes that the same people who are needed by the US economy are needed by the Mexican economy. In other words, that a country with 50k$ GDP per capita has the same needs as one with a 15k$ GDP per capita. It is very likely that Mexico has more talented people who couldn’t have afforded training in good job skills, and therefore higher-quality semi-skilled tradespeople.
Note that I am not saying that legalizing will make the US better off. I don’t know enough to have an opinion. I am saying that the argument in the meme is invalid because of the unexamined assumption.