Based on personal experience, I can tell you that people saying foolish things to those who are grieving, saying things that make it worse or that cause pain, is something that is much too common.
There are a number of reasons that happens.
* the speaker is feeling confusion caused by pain and shock at what has happened to you. This appears, to me, to be the biggest reason people say things that are confused, cause pain or don't make sense. If you are suffering from terrible tragedy and someone says something foolish, that hurts, I would suggest that the best starting place for thinking about what they've just said is that they are confused and in pain on your behalf.
* the speaker suffers from shallowness and lack of knowledge and perspective and the lack of self discipline to stay silent. I have always tried to be grateful that they have not had the experiences that would have taught them better.
* the speaker suffers from self absorption and the desire to put the other person out of the speaker's misery by saying something that comforts the speaker and allows them to move on in their bubble.
* the speaker suffers from narcissist behavior and the need to re-assert their central place in the world. Your pain has interrupted that and they are trying to re-establish what they believe to the proper order of things. I was always glad I wasn't the speaker. When someone says "you just buried a child? That is nothing compared to my suffering" and then proceeded to tell me about the hang nail they just had, or something similar, I would remind myself to be grateful I did not suffer from the mental and spiritual illness the speaker had.
* the speaker suffers from utter fecklessness and a willingness to harm others for some benefit to the speaker.
So, your child was murdered and someone starts trying to sell bullet proof vests for children using the tragedy (or to make any political or other point at their expense -- especially ones you do not agree with). /Sigh. People can't help themselves. Some really think they are helping others as well.
However, all of that said, I would like to emphasize that as we hear what people say about the tragedies that others experience I would suggest that it is better to assume confusion and pain than fecklessness and sociopathy.
So, what should you say?
It is easy to say, "I'm so sorry. I don't know what to say, but I'm so sorry for your loss." That is always the safe thing to say.
"Tell me about ...." is also good, if you are willing to just listen.
Those are two starting places, two good places, in all the other things people say and do and speak.