The number of input features to your linear layer is defined by the dimensions of your activation coming from the previous layer.
In your case the activation would have the shape [batch_size, channels=16, height=5, width=5]. In order to pass this activation to nn.Linear, you are flattening this tensor to [batch_size, 16*5*5].
The 16 is defined by the number of out_channels (i.e. number of filter kernels in the previous conv layer), while 5x5 is the spatial size defined by the conv and pooling operations performed on your input data.
Let me know, if you need more information!