I think everyone has met someone like this at one point in their life, a person who can't seem to help but make digs at other people or ask questions they must know will be painful for the person.
I totally get that once in a while we all say something clumsy or a bit tactless, usually its not intended to hurt anyone and if someone says something like that and its just a one off then I let it slide because if someone means to hurt you they will usually keep at it.
However when someone does keep it up, with repeated attempts to hurt you over the course of a conversation or each time they see you then or they do it to others as well then I think this really says more about them.
I don't know why they do it, I suppose it maybe that some people just lack insight, self awareness or any emotional intelligence. In some it might be part of cognitive decline or just a general lack of social skills but usually in this case if there is no malice you can tell.
So why do people do it? Why would you actively try to hurt or upset another person, repeatedly? I can only think that they must be so unhappy in themselves that it's only by trying to make others bad that they can feel better. Its quite sad really.