I have a cube that I am successfully rotating by mouse drags with the following algorithm:

Initialize rotation matrix to identity

Multiply worldspace yaxis (0, 1, 0) by inverted rotation matrix to get a vector in object space corresponding to the yaxis. Then rotate a bit around this vector given the mouse drags.

Same thing for xaxis.

Each update, apply rotation matrix to object.
This works fine, I am just having trouble understanding the theory behind why you can get the yaxis in object space by multiplying the yaxis in world space by the inverted rotation matrix. Can anyone explain this in very simple terms  I must be missing a key concept.
Thanks!