This weekend, I saw a news story on TV where a doctor was explaining that, while melamine is most likely safe in these trace amounts, it "has no business being in baby formula" because there's no benefit to the baby, there's a risk of harm, and you just don't need it to make formula.
My immediate reaction was: Okay, if it's so bad, there must be some reason producers would want to include it. After all, businesses don't e.g. pollute just for fun; they do it because that improves product quality and/or cost -- er, at least it appears that way to the most highly-visible parties.
As the story continued, the doctor answered my question by saying that it's included in order to fool the tests used to determine protein content. I don't remember the channel, but I found a San Francisco Gate story substantiating that claim:
Melamine contamination became major news when it was discovered that China was adding it to milk to disguise test results that measure protein levels. Since the chemical was found in infant formula in September, it has sickened some 50,000 Chinese infants and killed 4.
So there's our answer! They use melamine instead of the good stuff in order to pass some protein measurement test. And they only use melamine because it's cheaper, or else what's the point? But, that test has a "blind spot" that will give a "pass" rating to baby formula that only achieved that rating by compromising the "design constraints" of baby formula! So it fits into my template of "compensate for inflation by debasing the product instead of raising the price".
Now, it certainly doesn't take a bout of inflation to make people try to get "something for nothing". But it's a very plausible suspect for why it wasn't tried before.
Of course this is not to take away from the culpability of those who conjure up such unethical policies. And, to some extent, you have to understand the position they're in: when consumers reward those who can keep the visible price low, while ignoring the other costs thereby incurred ... well, don't be surprised when they're all too willing to oblige :-/