What's the best way to resize tensors for alignment purpose?

Using an nn.Linear layer could be a valid approach. You could add it as a trainable layer into your model and apply it in the forward function via:

def forward(self, X1, X2):
    X1 = self.linear(X1)
    # X1.shape = [5, 17]
    x = torch.cat((X1, X2), dim=0)
    # x.shape = [10, 17]
    x = self.layer(x)
    ...