My team is going to have a lunch at a local restaurant tomorrow to celebrate our recent achievements. The team is myself, three coworkers and my boss. The problem is my boss has made racist and sexist remarks during work hours so I definitely do not want to get on a personal level with him. How can I avoid attending without causing an incident with HR? Being frank about the problem would probably cause future friction with my boss which I do not want to make worse than it already is.
First of all, racist/sexist remarks in the workplace are red flags that ought to have you go to HR immediately, especially if it is a supervisor (rather than just a peer).
Avoiding a team celebration lunch (a textbook "team growth / building") activity is not your only real problem here.
Making excuses to not go is only delaying the inevitable : Your manager will soon flag you as a poor "team player" as from his perspective, you're appearing aloof and non-cohesive during team social gatherings.
Best case: He/she is eventually going to schedule a one-on-one to get to the bottom of this. You'd have to prepare for some awkwardness if you are going to let him know what is making you uncomfortable.
Worst case: He/she gets easily offended (adding poor emotional intelligence to his alleged racist/sexist character flaws) and starts to take it out on you passive-aggressively.
If you enjoy every other aspect of this job and think an apology would make your working for him comfortable again, I'd think it best to approach your manager and give him a chance to explain himself / correct this behavior.
The only other two options are HR directly (complicated but the right thing to do in many cases) or looking for a new position within or outside the organization.