The Latin from which French evolved has duo, duorum/duarum, duos, and so on, while the contemporary French pronunciation also omits the 'x'. Why did Middle French spell deux with an x?
It is due to a confusion. In the middle age, the custom was to abbreviate the words ending by -us into -x. So "deus" was written "dex", this tradition was kept, but, afterward, it was added a 'u' into "dex". For further information: https://fr.m.wikipedia.org/wiki/Abréviation_médiévale#X_(-us)
It comes from the Latin accusative plural masculine: duos. The oldest spellings in French are duos and deus, then deux, with x as an alternative spelling for final /s/, as in dix, yeux, and many other words. It is not true that the contemporary French pronunciation "omits the x"; the x is still pronounced (as /z/) in liaison.
More here: http://www.cnrtl.fr/etymologie/deux