If someone is limping very badly, or grimacing, or breathing strangely, or clutching some part of themselves in agony, I'll check they're okay and ask if they need a marshal's assistance. If they're just walking reasonably normally I'll either say hi (in a very small race where it seems somehow rude not to acknowledge each person you see) or just run past and leave them to it (in races with loads of people).
If I'm walking in a race it's most likely cause I've blown up or pulled a muscle, or cause I'm taking a scheduled walk/nutrition break. Or sometimes just cause I'm admiring the scenery in a place I've never been before. I don't really appreciate people urging me to 'keep on running' in any of those circumstances. In fact, it pisses me right off. One of the reasons I prefer small races to big city ones. I can't stand having to listen to "you're nearly there"s from the first half mile of a marathon!