Yes, the Nikon Z9 can automatically capture images for focus stacking but the feature you need to use is called Focus Shift Shooting. In this mode the camera can shoot up to 300 images with a shift in the focus between each shot. You can set the size of the focus step in the Focus Shift Shooting settings page of the menu. Helpfully, you can also select to save the images to a dedicated storage folder so they’re easy to find when you some to download them ready to composite them into a single image with depth of field that runs from front to back.