Then I don't get why it happens.
I understand that Spinner and Datepicker can be in different containers, in which case, I guess you can't do anything.
But if Datepicker and Spinner have the same container, and both have z-index computed from this container's z-index, it should be possible to make the Datepicker's z-index greater than Spinner's one.

That's just not true. Even if both widgets used that approach, they'd end up with the same z-index, which would cause problems. So far, in the 5 years of jQuery UI being around, nobody has found a solution that just works. It's up to you, the person building the page, to set the z-index appropriately for your specific situation.