How to remove the effect of current rotation while rotating a bone (Python)?
Relative vs Absolute.

The "accumulative" nature is the nature of a 3D transform, ie rotate the bone from where it is by this much about an axis.  

Whereas you wish to set the absolute rotation.  

As well as using method in accepted answer, contend you could also pre-set the rotation to zero before applying any transform, for example if the rotation mode is euler

posebone.rotation_euler = (0, 0, 0)


Zeroing before applying a rotation will result in an absolute value.  Could say, absolute is relative from zero.

Matrices

The following will zero rotation of a pose bone, regardless of its rotation mode, Euler, Quaternion or Angle Axis.

Using matrices can zero the rotation by finding the inverse of the rotation part of the matrix and pre or post multiplying. The inverse of a rotation matrix is the relative rotation to apply to rotate back to zero.

The top left 3x3 submatrix of a 4x4 transform matrix is the rotation part.  A rotation matrix is orthogonal, hence the transpose is also the inverse (a cheaper calculaton)

&gt;&gt;&gt; pb = C.object.pose.bones['Bone']
&gt;&gt;&gt; M = pb.matrix_basis.to_3x3().transposed().to_4x4()
&gt;&gt;&gt; pb.matrix_basis @= M


To set the rotation from whatever to 22 degrees about Z in whatever rotation mode

&gt;&gt;&gt; R = Matrix.Rotation(radians(22), 4, 'Z')
&gt;&gt;&gt; M = pb.matrix_basis.to_3x3().transposed().to_4x4()
&gt;&gt;&gt; pb.matrix_basis = R @ M @ pb.matrix_basis


or similarly using below as rotation matrix, will set a pose bone of any rotation mode to the euler equivalent without the need to set the mode. 

&gt;&gt;&gt; R = Euler((0, 0, radians(22)), 'XYZ').to_matrix().to_4x4()


Why?  what if I don't want all the bones changed to 'XYZ' Euler, and instead want to keep all as assigned, using above can keyframe with something like

pb.matrix_basis = R @ M @ pb.matrix_basis

if pb.rotation_mode == 'AXIS_ANGLE':
    pb.keyframe_insert("rotation_axis_angle")
elif pb.rotation_mode == 'QUATERNION':
    pb.keyframe_insert("rotation_quaternion")
else:
    pb.keyframe_insert("rotation_euler")