I went through the Blender's source code, but wasn't able to find how the local orientation of each bone is calculated based on its the head and tail (I thought I should specify that I'm talking about orientation in bind pose).
I'm guessing that Blender uses axis angle rotation. When your pull a tail towards certain direction, I suspect it calculates the rotation axis and angle from the bone's old direction it was facing towards the new direction. And the direction itself is the difference of tail and head position vectors.
As you move the tail or head around the roll is introduced implicitly. But you can also change the roll explicitly. Which is done by rotating the bone around its forward axis aka the direction its facing.
Could someone more skilled with Blender explain to me if this is actually how the local orientation is calculated for bones in Blender?