ragas:

Why we are having 10 in first convolution layer? Generally output of first conv layer is given by (W−F+2P)/S+1.


You seem to be confusing Spatial output vs Channel Output. The number 10 and 20 represent channels. The spatial output size is calculated from the formula you mentioned (if you have dilation factor, that is also considered in pytorch)
Sequenctially this is what is happening

(28x28x1) -> conv1 -> (28-5+1) -> (24x24x10)
(24x24x10) ->max1 -> (24/2) -> (12x12x10)
(12x12x10) ->conv2 -> (12-5+1) -> (8x8x20)
(8x8x20) -> max2 -> (8/2) -> (4 x 4 x 20)
(4x4x20) = 320 -> Linear -> 50
50 -> Linear -> output_dim