To understand why 13 being a woman makes narrative sense, we have to look at Missy. Missy has been a huge part of the 12th Doctor’s life. He and Missy spent the beginning of his run playing their old chess game, trying to outwit each other with the world as the stakes. It was similar to the relationship he had with the original TV Master during the 3rd Doctor’s run. Then, here and there, Missy would help, in her own way. Things only escalated when the Doctor had to spend years guarding her vault. They would get take out, sit around the little space heaters and talk, sometimes Missy would play the piano for him. She would even offer advice to him and soon be trusted enough to take his crew out on runs to save people.
Missy was the first regeneration of the Master to truly come close to being Koschei, the boy the Doctor grew up with, his old university roommate, his best friend. Missy was the first Master to allow herself to be seduced by hope and good. She became all that the Doctor ever wanted Koschei to be, a friend that would stand beside him and use all of her brilliance to do the right thing-for once.
Now let’s look at the end of the 12th Doctor. At the end, he is desperately against the change. He has finally become the person he wants to be, after so much struggle, and now he has to change again. He’s afraid of what he will become next, afraid to lose himself. There is already beautiful meta about how his entire arc was getting to this point of being kind and selfless, and how it paralleled Bill’s struggle as a cyberman, so I won’t go too far into it. In that moment of fear, it only makes sense that he would think about Missy and be inspired by her change and thereby, follow her lead in the hopes it might work out the same.
With all that in mind, I look forward to seeing what kind of Doctor the 13th will be and whether or not this choice leads to what 12 was hoping for.