This method sorts the Points according to the parameter value of the polycurve.
So if a point’s “closest point on the curve” towards that point is near the start, it will be sorted in front of points near the end. Like this:
Rebuild the curves as PolyCurve.ByPoints and you will get a more accurate point closest to result. I think that is the step that is missing and causing problems.
The connections are falling on top of eachother at the corners, which is throwing off the sorting. Building a polycurve by consecutive points (as @simon_murphy1 indicated) may resolve this. Alternatively using a shape which respects the corners cleanly. Would likely take a lot less time to draw that as a filled region that number these by hand.