Transforming armature bone by matrix of another bone in pose mode
The solution to this was to transform bone2 by the inverse of bone1's pose mode matrix, then transform bone2 again by bone1's matrix in edit mode:
for b in bpy.context.selected_bones:
    b.transform(hand_pose_mat.inverted())
    b.transform(hand_edit_mat)