Procrustes in Blender
First of all, I would suggest using the letters A and B, instead of X and Y. Furthermore, you don't document what type they are; I assume those are matrices. You can call X.to_euler(...) to get the rotation from the matrix, and assign it to ob.rotation_euler.

For more info, see the mathutils API documentation.