Southern England was occupied by Saxon tribes and divided into Wessex (West Saxons), Sussex (South Saxons), Essex (East Saxons) and Middlesex (the central Saxons).
So how does the word Saxon become -sex? Why not Middlesax?
As a native Middlesexian (Middlesaxon?) I can say that i’ve heard it pronounced in many an accent and find it very easy to believe that it could just be a shift in pronounciation.
The transition to Middle english from Old english basically squashed all diphthongs into monophthongs and /ea/ turned into /a/. We can see it at work in other words like weax and healf which became wax and half. As to why the diphthong /ea/ became /a/, I do not know.
Of course, neither Wessex nor Middlesex exist any more as counties (though the latter may still be used in postal addresses. Sussex still exists, but in “reality”, The Only Way is Essex.
I always thought it was ‘sex’ as in ‘section’. Middlesex would be the section west of Essex (east section), north of Sussex (south section) and east of Wessex (west section). But apparently, I’m wrong.
When Cholmondely can come to bepronounced “chumley” and Leicester can come to be pronounced “lester” and lieutenant can come to be pronounced “leftenant” jumping from sax to sex doesn’t even begin to be inexplicable.