How is the weight matrix set and its dimension in CNN
The 1176 is the number of neurons in the layer before the last layer, which is the number of pixels in the convolutional layer but flattened (height*width*n_filters, i.e. 7*7*24=1176). The 3 comes from the number of neurons in the final layer, since you have 3 classes your final layer has 3 neurons, 1 for each class (which will output zero or one). This then gives a weight matrix of 3x1176 for the weights between the second to last layer and the last layer. Using torch we can show the dimensions of the data passed between the layers in the network. In the example below I have omitted the batch normalization and relu layers since they do not affect the dimensions. The dimensions are defined as follows: batch_size * n_channels * height * width.

import torch

x = torch.randn(1, 1, 28, 28)
x.shape
# torch.Size([1, 1, 28, 28])

conv1 = torch.nn.Conv2d(in_channels=1, out_channels=12, kernel_size=3, padding=1)(x)
conv1.shape
# torch.Size([1, 12, 28, 28])

pool1 = torch.nn.MaxPool2d(kernel_size=2, stride=2)(conv1)
pool1.shape
# torch.Size([1, 12, 14, 14])

conv2 = torch.nn.Conv2d(in_channels=12, out_channels=24, kernel_size=3, padding=1)(pool1)
conv2.shape
# torch.Size([1, 24, 14, 14])

pool2 = torch.nn.MaxPool2d(kernel_size=2, stride=2)(conv2)
pool2.shape
# torch.Size([1, 24, 7, 7])

pool2.view(-1).shape
# torch.Size([1176])