Fix dangling pointer in internals::registered_types_cpp_fast from #5842 (#5867)

* Fix dangling pointer in internals::registered_types_cpp_fast from #5842

@oremanj pointed out in a comment on #5842 that I missed part
of the nanobind PR I was porting in such a way that we could have
dangling pointers in internals::registered_types_cpp_fast. This PR
adds a test that reproed the bug and then fixes the test.

* review feedback, attempt to fix -Werror in CI

* use const ref, skip test on python 3.13 free-threaded

* Skip test on 3.13t more robustly

* style: pre-commit fixes

* CI fix

---------

Co-authored-by: Joshua Oreman <oremanj@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
7 files changed