Did you watch Tennant's era? Specifically, Series 4? Well one of the episodes (well, two, it was a two parter) was set in a massive library. River Song debuted (and died) in this two parter. BUT her consciousness/mind was saved onto the Sonic Screwdriver before being uploaded to the database in the library (I believe the database was created to contain the consciousness of a little girl who died? and the library was built because she loves books? honestly that story was a fever dream). I think this was brought up during Smith's era during Name of the Doctor - I'm pretty sure River's presence was her consciousness from the database - not physically her.
i guess 12 will be still stubborn to go, so instead of 'dying', he uploads his consciousness to the library so him and his past selves can live freely and switch between faces as they so wish, and the consciousness will switch from Capaldi to Smith to demonstrate the fact they can change, as Smith is the only one young enough and cares enough to return