The ES-52 works a little differently than most lens hoods we are accustomed to seeing. Instead of blocking off-axis light by extending a cylinder or cone perpendicular to the image plane and centered around the optical axis, The ES-52 blocks extraneous light by placing a smaller circular opening parallel to the image plane. Due to the difference in design, perhaps it doesn't offer as much hazard protection as a conventional design would. This is balanced by the fact it preserves the compact size of the EF 40mm f/2.8 STM which is one of the drawing points of this lens.
As with all lens hoods designed for EF lenses, the OEM hood is designed for the angle of view needed for use on a camera with a full frame sensor. If you are using an APS-C camera, the hole on the middle of the hood could be even smaller since the angle of view needed is narrower. This would be the same as aftermarket conventional hoods for other lenses that extend further out for use on APS-C cameras.
I have seen a few reports that the ES-62 hood (including thread adapter) designed for the EF 50mm f/1.8 II will also fit the threads in the 40mm pancake lens, but you then lose the compactness of the 'pancake.' Since the EF 40mm f/2.8 STM provides a narrower FoV on an APS-C camera than the EF 50mm f/1.8 II does on a full frame camera and the front element of the 50mm lens is recessed from the hood mounting point and wider than the front element of the 40mm lens there should be no issues with vignetting if you choose this option. Without comparing them side-by-side, though, it would be hard to say which one provides the narrower and wider angle of protection from off-axis light when mounted on the EF 40mm f/2.8 STM.
Here's a very crude conceptual drawing that illustrates how each type design blocks extraneous light. Please note that this is not to scale for either of the actual hoods. Light from point sources outside the yellow lines of each cone but inside the orange ones would fall on part, but not all, of the front element. Light from outside the cone formed by the orange lines would not fall on any part of the front element.