Yes, it should be optional.
General PE/exercise should be compulsory, but a competitive event in front of parents, when children feel humiliated, doesn't encourage a love of sports/exercise.
It also doesn't teach resilience to simply be routinely humiliated, which is what often happens. There's no 'teaching' involved. If children were taught how to improve at sports, were allowed to do non-competitive activities, were given optional chances to compete in races at the right level, and actively taught about sportsmanship and helped to come to terms with feeling bad about not winning something, that would be different. But many sports days are not like this. They involve humiliation, year after year, in front of an audience, and the experience of coming last (and in some cases, the active feeling of others that the academic children who happen to be bad at sports need 'taking down a peg' by showing them they are bad) is just supposed to in itself teach resilience. I think is just teaches them to hate sports, to hate competition, and to feel bad about themselves.
Let children who enjoy competitive races do them in public with an audience. The others can do non competitive activities, or activities without the whole school watching, or get actually taught how to run/jump better, or learn to find other physical activities fun so that they might carry them on in future.