Solved by ptrblck in post #2 
              
              
                The 5*5 are not derived from the kernel size, but the spatial size of the input to the linear layer, which is apparently also 5*5. 
You can add a print statement right before feeding the activation to self.fc1 to see the activation shape, which should be [batch_size, 16, 5, 5] before flattening.