Try to convert your numpy image to a PIL.Image:
import torchvision.transforms.functional as TF

transform = transforms.RandomCrop(24)

x = np.ones((3, 50, 50), dtype=np.uint8)
x = x * 255

x = torch.from_numpy(x)
x = TF.to_pil_image(x)
transform(x)

As a side note, I think your transformation won’t work correctly, since now transform is called sequentially on the image and mask, which will sample different random values for your random transformations.
Your image might therefore be cropped using another position than the mask.