I wasn't able to reproduce your crash, but there is definitely a problem - when using --enable-shared and --with-jemalloc together, the Ruby that gets built still uses libc's malloc and ignores jemalloc. This is because we pass -ljemalloc to the link line for libruby.so, but we don't pass it to ruby. This means that the built Ruby isn't marked as needing libjemalloc.so:
root@jammy-189dc9d584290f1a:/var/ruby# readelf --dynamic ruby | grep NEEDED
0x0000000000000001 (NEEDED) Shared library: [libruby.so.3.3]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
And because the dynamic linker (at least the glibc one) links libraries in breadth-first order, that means that libc.so.6 is linked before libjemalloc.so.2:
root@jammy-189dc9d584290f1a:/var/ruby# ldd ruby
linux-vdso.so.1 (0x00007ffe873fb000)
libruby.so.3.3 => /usr/local/lib/libruby.so.3.3 (0x00007f8870000000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f886fc00000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f887054c000)
libjemalloc.so.2 => /lib/x86_64-linux-gnu/libjemalloc.so.2 (0x00007f886f800000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f8870512000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f886ff19000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8870572000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f886f400000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f886fef9000)
We need to pass -ljemalloc to the linker command line for the final Ruby executable. I'm playing around trying to find the right Autoconf magic spells for this now.