All transformations are applied relative to the origin. If you set the origin to the top left corner (default) your rectangle shape will rotate around the top left corner. If you set the origin to the middle of the rectangle shape it will rotate around its center.
As such the origin is local to an object and if you "copy" the origin of another rectangle shape, you'll just copy the local origin. If you want to rotate around another object, you need to use the global position instead:
rect2.setOrigin(rect.getPosition());