How to react when encountering students who have previously failed my course? Context: I am an assistant professor of mathematics at a small liberal-arts college in the US.

I did my graduate work at a large public university, and there I rarely encountered students who had previously taken a class from me, let alone ones who had failed one of my courses.  Now that I'm at a much smaller institution it happens somewhat frequently, and I've only finished one semester here!

At this time I have no idea how I should react to these encounters.  Generally former students and I exchange a pleasant greeting, but I find myself instinctively trying to avoid students who've failed because I'm afraid that they are still angry at me, I don't want them to feel bad, etc.

The title of my question says it all: How should I react when encountering students who have failed one of my courses?  I could simply treat them like any other student, but I'm concerned about reinforcing the stereotype of "the tone-deaf mathematician with poor social skills."

Perhaps this question is a better fit for the interpersonal stack exchange, but I figured I'd start here.
Since you are at a small liberal arts college, I think you should not underestimate how much your own actions contribute to the culture of the college community. The notion of "avoiding" students is not something that you or your college wants to be known for (I imagine)! I think it is always best happily greet students that you know, perhaps ask them how things are going, etc. On some level, this kind of pleasant behavior is a professional obligation.

I don't think you should act any differently towards students who have failed your course (vs. students who did not fail, or haven't taken a course from you, etc.). Be cordial, and if the student wants to avoid you, then let them.

I will add that, while it's possible the student is mad at you, they may also be some combination of embarrassed and mad at themselves for failing. If they are embarrassed, then you avoiding them might make them feel worse, and you engaging with them might help them to get over the embarrassment.