Distance matrix with different length sequences
There are two possibilities:


Do not use the sequences per se but a scalar metric of sequence similarity for distance values
Introduce gaps in the alignment. You can also do an end to end gapped alignment such as the Needleman-Wunsch and use the alignment scores for the distance matrix.