The automatic lock/unlock function is triggered by proximity of a magnet embedded in the case cover. The position of the iPad sensor (and hence the magnet that interacts with it) is critical - and often differs between iPad models.
If you are using the same case with your new iPad Pro 13" M4 as is being used with an older iPad Pro 12.9" model, the magnet in the case cover is very likely to be incorrectly positioned for your new iPad.
As such, unless the case that you are using is explicitly designed for the iPad, the automatic lock/unlock function is unlikely to work.