Image is unfortunately ambiguous, I assume this means that the distance between A and B will always be 4-5 cm. The text may also mean that the movement itself is 4-5 cm, but that leaves me guessing the actual distance between the plates.
So at 4-5 cm distance:
Ultrasound may or may not work - it's on the low end of the range of an HC-SR04, the thickness of the sensor may become an issue (as it brings down the effective distance to about 3 cm, while the minimum it can range is 2 cm) and the 1 cm difference is close to the typical error you see in measurements. It being steel plates should give really clean echoes though, which is why it may work.
IR/laser: too close, their minimum distance is about 1 meter.
Magnetic: you should be able to make this work with two metal plates, the distance is not too much but your sensitivity will have to be very high - to the extent that if you breath over it (increase humidity/temperature of the air) you will detect it. You'll also detect your hands getting within about 10 cm of the device. You'll detect just about anything that's placed in between the plates. So environmental factors are such that you may not be able to do a reliable measurement.
So indeed at a 4-5 cm range we're down to mechanical options.