This is a somewhat bleak short story that I read about five or six years ago, in a collection of stories all by the same author that, based on printing style and binding was probably printed between 1950 and 1980.
The story was about a society where everyone lived underground (or possibly just in sealed environments without exposure to sunlight). Everywhere in this society were various robots, which were constantly present among the people in the society, but which were almost never mentioned by or acknowledged by anyone, as this was considered impolite. From time to time, and for reasons that nobody could really figure out, one of the robots would reach out and kill someone near it.
The protagonist of the story was keenly interested in the reasoning behind the robots' choices of who to kill, and the story is about his efforts to work out that reasoning. He goes through various theories, all of which are disproven over time, and eventually decides that the robots don't like the complacency exhibited by the rest of society.
He starts to explore old, unused parts of the underground complex, finding tunnels that go far from everyplace anyone uses. Eventually, after years of exploration and having reached a very far tunnel, he encounters a lone robot. I want to say that it's sitting at an exit from the complex, but I'm not sure -- it may have just been sitting in the middle of a tunnel. The man, triumphant, approaches the robot to say that he's figured it out and passed their test.
At that point, the robot kills him.
I'm pretty sure that the author was male. I'm also pretty sure that the author wasn't a big name in sci-fi but not exactly obscure, either.
EDIT: In response to DavidW's (funny!) comment, I should point out that I don't believe this was intended as a dark comedy. My interpretation was that the robots were a metaphor for death in our everyday lives, i.e. the possibility of suddenly dying (e.g. via heart attack or traffic accident) is always there, but, even though death is inevitable, it's a semi-taboo subject. Also that it was implied that the robots have no plan and that the protagonist's efforts to discover one were a pointless project (which is why I called the story "bleak").
EDIT: I've been trying to remember more about this, and I believe that it might have been a sci-fi story in a collection that was NOT primarily sci-fi. That might mean that the author is a more recognized name in the horror genre than in science fiction.
I think that the first story in the collection (or at least one of the first few stories) ended with the narrator being tied up in a dark, abandoned building full of hungry rats. The narrator was a newly-released convict who was trying to find out where one of his cellmates (who died in prison) had hidden the money from a successful robbery, but he was double-crossed by the cellmate's ex-wife. (I'm not really interested in this story, but I'm about 90% sure it was in the same collection.)