You can’t please everyone.
You could have it that heats/selection are behind closed doors, then only the ones that want to compete will be “on show”.
But some might still be upset that their parents weren’t there and they didn’t get to race.
Our school had “fun” races as well as competitive races - 3 legged and egg and spoon etc. But if you’re not sporty, you’re unlikely to somehow be good at these either. And they take tortuously longer. At least flat races are over quite soon.
My children didn’t enjoy it. They were sanguine about coming last though. They totally expected to, so that part didn’t upset them.
I was always last too. I personally hated that the parents would shout encouragement and clap me the loudest. It felt that it was drawing attention to me more.
But some children probably enjoy being acknowledged and encouraged.
I don’t think it should necessarily be optional though. Most things at school aren’t optional after all!
I think I think the best way is grouping by ability a bit. Get rid of the humiliating “fun” races that take up lots of time.
Let the slower ones race against each other, then it doesn’t look so obvious, and some of them can still win a medal.
Or maybe split sprinters and longer distance runners, again slower ones might do better over a longer race. It could be going on at the same time as the sprints.