Khelif would need the means to take on a legal battle.
Algeria would probably have to step in to provide that. If Khelif is male, do you think they'd want the publicity of that?
The IOC (currently) don't want the spectacle of a legal battle either. But it could be out of their hands if one of the female competitors decided to take action for some reason. This could change the dynamics, especially in view of a positive test as male.
And this is a subject very much in flux and changing rapidly. We are now starting to see open protests in California against unfair practice in women's sport. That wouldn't have happened just a year ago.
As awareness grows and the fear lessens, public anger will rise and calls will grow for this to be addressed.
We don't know where we will be in 10 or 20 years. I can imagine a scenario where the IOC eventually publicly calls for the return of the medal, revokes it on paper and issues new medals for the women who placed below. Khelif might then refuse to return but this doesn't mean Khelif would go legal to dispute this or the IOC would go legal to physically retrieve the medal. The legal stuff doesn't necessarily even matter for this reason...