To track this, I opened
https://github.com/sagemath/sage/issues/40890
In short, the major issue is in src/sage/cpython/atexit.pyx, which was
written using Python C internals, which have been changed quite a bit
over time,
and this change had been quite big in Python 3.14
(I'd argue it was never a good idea to rely on non-public API, but, well,
here we are.)
The code in question is used in doctesting and in docbuilding, so the
rest is independent on it, and I was able to build the rest, after
disabling this code.
(and quite a bit of package version bumping, in
https://github.com/sagemath/sage/pull/40892 - which is ready for
review)
There are more details given in #40890, and we need to decide how to proceed.
(the authors of atexit.pyx aren't active in the project any more, and
it needs more than just a small patch)
Dima