When she was a girl, growing up in rural South Africa, the runner Caster Semenya would sometimes face a humiliating ritual before a race. She grew accustomed, her coaches once said, to having to retreat to the bathroom with a member of a suspicious rival athletics team and physically show them that she was not a boy. From her childhood, people had gossiped about her body; by the time she had begun competing internationally she must have been used to the whispers, the open stares in changing rooms.

All her life she has been portrayed as a freak, an anomaly of nature undeserving of her gold medals. And as if having her femaleness constantly questioned wasn’t enough, as a black South African athlete and a lesbian she attracts more than her share of kneejerk prejudice. To argue that this Olympic athlete has somehow had it easy because of her biology feels grotesque, in the circumstances. But nothing about this case is simple.

This week Semenya lost a landmark battle to be allowed to compete in the body she was born with, when an International Association of Athletics Federations (IAAF) ruling that she must take medication to lower her testosterone levels if she wanted to race in women’s events was upheld. Semenya is widely understood to have been born with intersex traits, meaning she produces unusually high levels, for a woman, of the hormone that boosts strength and speed.

Nobody knows for sure how having to dope herself would affect her performance, but over the distances she runs, a few seconds is the difference between coming first and last – and that leaves her with an extraordinarily painful choice to make. The race she ran in Doha on Friday night was almost certainly her last chance to compete as what the legendary tennis player Billie Jean King called “her authentic self”. Whether or not this week’s ruling was the right decision for her sport, more broadly, on an individual human level, it feels disturbing. How could anyone emerge unscarred by such an excruciatingly public repudiation of her body and identity? And how must it feel, for anyone who identifies with her particularly contested status, to watch this unfold?

‘Athletics is the one arena in which a body for which she has been so cruelly ridiculed worked gloriously in Caster Semenya’s favour.’ Photograph: Cameron Spencer/Getty Images

For many of the athletes she has been beating for years, not to mention those anxious to keep politics out of sport, this argument doubtless feels intensely frustrating and unfair. The blunt truth is that without sex segregation in sport, women would never win medals, and segregation can only work if there is an agreed definition of what makes someone biologically male or female. There is no room on the track for the grey areas and blurred lines increasingly emerging in real life, even if the boundaries created by the IAAF look increasingly crude and artificial by comparison.

And in theory at least, saying that Semenya can’t race in women’s events as her natural self shouldn’t be taken as implying that she is not a woman. Sport is sport, not the whole of human existence, with practical requirements peculiar only to itself. Yet, however much athletes wish it to be, sport is not quite so easily separated from the society that invented it or from broader notions of fairness.

In the nicest possible way, all Olympians are freakish, capable of things you or I couldn’t do if we trained for a lifetime. But for many, what this case illustrates is the way some anomalies are celebrated and others are not. A swimmer who naturally produces unusually low levels of lactic acid from his pumping muscles or a skier whose body just happens to generate freakishly large numbers of blood cells can still take their rightful place on the podium. But hormones, that most angrily contested aspect of female biology, seemingly fall into a different category.

However sound the reasons for treating intersex traits differently from other genetic advantages, women who have been judged on whether they are womanly “enough” – enough to be loved, enough to be socially acceptable, enough to get a job in an industry where male customers like to look at them – may unsurprisingly bristle at the sight of another woman being judged in this way. And that goes double for black women, who have for so long been made to feel that they can’t live up to a white western ideal of female desirability; who have been reminded every time they have flicked through a magazine or browsed a beauty counter that their bodies, their hair, their skin are somehow all wrong. Bodies are battlegrounds, and not just in athletics.

‘Sport relies on strict binary divisions between men and women. Yet society is drifting away from them.’ A rally in support of homosexual and transexual rights in Berlin, 2018. Photograph: Hayoung Jeon/EPA

And this, arguably, is only the beginning. Semenya’s case is, strictly speaking, separate from that of whether trans women should compete in women’s sport, since it revolves around how far testosterone drives performance. For trans female athletes, whose hormone levels will have already been lowered by transitioning, the debate centres more on whether some advantages linger on from years of living in a body flooded with male hormones.

But both are different expressions of the same basic problem, which is that sport relies on strict binary divisions between men and women to create a level playing field. Yet society is drifting away from them, thanks not only to the shifting sands of gender identity but to greater medical understanding. There have almost certainly been elite sportswomen in the past with naturally sky-high testosterone levels that we simply didn’t know about. Semenya’s bad luck – and in some ways that of the experts asked to pass judgment on her – was to be born into a generation equipped with a more sophisticated but still incomplete scientific understanding of body chemistry, and vast anxiety about what it all means. Suddenly, sport’s sexual sorting hat is throwing up confused answers, and untangling them is a job for ethicists as much as for doctors.

Semenya’s case has now seemingly run its legal course, but the debate it started has not. Letting an athlete compete with too much of an inbuilt biological advantage feels unfair to their rivals; stopping someone competing as the woman she naturally is feels monumentally unfair to her. There is no way of resolving the moral dilemma without someone ending up wronged. And while this time it has seemingly been resolved by backing the welfare of a majority over the welfare of one individual, that indisputably leaves a nasty taste in the mouth. Running is so very clearly what Semenya excels at, athletics the one arena in which a body for which she has been so cruelly ridiculed worked gloriously in her favour. If fair play has in any sense been restored to athletics, it’s hard to shake the sense that something important has been lost.

• Gaby Hinsliff is a Guardian columnist