They don’t need to be squared per se, but all the images in your batch need to be the same to allow for batch processing.
For example this is a standard transform that would resize the images to be 224x224 and make it suitable for a imagenet trained classifier:
transforms.Compose([
        transforms.RandomResizedCrop(224),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])

this would then be passed into the transforms argument when you create your dataset and would resize and make those other transformations for you as well.  You can see a worked out example of how this works at https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html.