The second example is using basically a 2D convolution where the kernel height is equal to the input height.
This code should yield the desired results:
batch_size = 1
channels = 1
height = 3
length = 10
kernel_size = (height, 5)

x = torch.randn(batch_size, channels, height, length)

conv = nn.Conv2d(
    in_channels=1,
    out_channels=1,
    kernel_size=kernel_size,
    stride=1,
    padding=(0, 2)
)

output = conv(x)
print(output.shape)
> torch.Size([1, 1, 1, 10])