This paper presents a cosmological analysis based on the properties of X-ray selected clusters of galaxies from the CODEX survey which have been spectroscopically followed up within the SPIDERS programme as part of the sixteenth data release (DR16) of SDSS-IV. The cosmological sub-sample contains a total of 691 clusters over an area of 5350 deg(2) with newly measured optical properties provided by a reanalysis of the CODEX source catalogue using redMaPPer and the DESI Legacy Imaging Surveys (DR8). Optical richness is used as a proxy for the cluster mass, and the combination of X-ray, optical, and spectroscopic information ensures that only confirmed virialized systems are considered. Clusters are binned in observed redshift, (z) over tilde ...