I heard once that all planes of the world - spiritual, emotional, and physical - parallel each other, with the physical world and its laws of nature stemming from the spiritual world and its reality.
We eat kosher because G-d told us that’s what is good for us spiritually. Because it’s good for us spiritually, in the parallel physical world, it must also be good for us physically. But we don’t do it because it’s good physically; we do it because it’s good spiritually, because G-d said. Any physical benefit is just a nice, welcome consequence.
But even if we’re keeping the letter of the law, we can still mess ourselves up if we ignore the spirit of the law.
Nachmanides talks about Jews who overeat and overindulge on kosher food. That’s not what we’re supposed to be doing, he says. Jews have the commandment to be holy - to serve G-d and be the representatives of a G-dly way of life here on earth. If you’re really making decisions with that in mind, you’re not going to be pigging out on unhealthy food.
Why don’t all Jews act like that all the time? Because we’re human, and our job is to slowly but surely grow into our G-dly potential. So even Jews who are aware and striving may not be holding at the level of only eating food that is healthy for them - or they may slip, and need to work their way up again.