Hi,
the warning you are getting seems to be raised by your loss function if you look at the end of your message [return F.mse_loss(input, target, reduction=self.reduction)]. This is because MSE expects that your prediction and your target are of the same shape. Maybe you can show us a bit of your training loop, so we can help you more.

And now to answer your questions:

Could somebody be so kind and explain to me how to choose the input size of this specific layer? How is it dependend on the output size of the previous layers?

When you go from a Convolution to a Linear-Layer you want to flatten your learned features, because a Conv2d Layer outputs a 4d-Tensor [B, C, H_out, W_out] and a Linear Layer takes in a 2d-Tensor [B, F_in] . Those features are contained in your Channel, Width and Height dimension, so you want them flattened to be equal to F_in (C*H_out*W_out = F_in).
Normally you can also apply something like a adaptive average pooling 4 before you flatten your input, because the height and width of the output of a convolution depends on the height and width of the input, which can cause C*H_out*W_out != F_in and you would get an error, because of mismatching shapes of the weights in your Linear Layer and your input. By applying adaptive average pooling you define the output shape of the input given to the AdaptiveAvgPooling Module. When you now flatten this output, its guaranteed to have the same Height and Width all time and C*H_out*W_out = F_in, will (hopefully) always be true.
PS: Maybe you can also have a look at Conv1ds, because mel-spectrograms are normally sequential data of shape [B, n_mels, time], but just saying.