I considered the two cases in figure:
In the first case I rotated the reference frame along z, I expressed x2,y2,z2 in function of x1,y1,z1, and I got a rotation matrix A:
| cos(g) sin(g) 0 |
A = | -sin(g) cos(g) 0 |
| 0 0 1 |
which is the transpose of the elementary rotation matrix along z:
In the second case I rotated the reference frame along y, I expressed x2,y2,z2 in function of x1,y1,z1, and I got a rotation matrix B:
| cos(b) 0 sin(b) |
B = | 0 1 0 |
| -sin(b) 0 cos(b) |
which is the elementary rotation matrix along y:
Why? I expect to get either A=transpose(R_z) and B=traspose(R_y) or A=R_z and B=R_y.
Thank you so much for your time.



Based on right-hand rule, in the first case the $z$ axis is coming out of the paper (if you swipe your fingers from $x_1$ to $y_1$ then your thumb points upward, indicating the direction of $z_1$). So while swiping from $x_1$ to $y_1$, your fingers pass $x_2$ indicating the positive rotation along $z$.
However, in the second case, based on the right-hand rule, the $y_1$ axis points inward so the rotation shown in the figure is actually along -$y_1$ axis not the $y_1$ itself.