Hi,
There is no mathematical difference between them, except the dimension of input data.
nn.BatchNorm2d 31 only accepts 4D inputs while nn.BatchNorm1d 42 accepts 2D or 3D inputs. And because of that, in features which has been constructed of nn.Conv2d layers, inputs are [batch, ch, h, w] (4D) we need BatchNorm2d and in classifier we have Linear layers which accept [batch, length] or [batch, channel, length] (2D/3D) so we need BatchNorm1d.
Two linked docs completely explain this idea.
Bests