How can I correct bone rotation with bpy between two Rigs which have different roll settings
For the ordinary case you might convert the pose matrix like this

import bpy

arm_src = bpy.data.objects['Armature_Source']
arm_tgt = bpy.data.objects['Armature_Target']

def mat_offset(pose_bone):
    bone = pose_bone.bone
    mat = bone.matrix.to_4x4()
    mat.translation = bone.head
    if pose_bone.parent:
        mat.translation.y += bone.parent.length
    return mat

def adjust_pose_mat(source):
    target = arm_tgt.pose.bones[source.name]

    mat = (mat_offset(target).inverted() * 
           mat_offset(source) * 
           source.matrix_basis)

    target.matrix_basis = mat

for pb in arm_src.pose.bones:
    adjust_pose_mat(pb)


Example Blend: