Hi Daniel,
In the first sentence, we are talking about a potential/future event. If it doesn't rain, they will go to the races. If it rains, they won't.
In the second sentence, we are talking about an event in the past. They didn't go to the races because it rained. They would have gone, if it hadn't rained.
Best wishes,
Jon