How do automatic cameras know the right depth of field?
The short answer is, "They don't." They, or more specifically the designers who wrote the camera's firmware, guessed at it.
Different cameras use different solutions to arrive at the shutter speed and aperture when shooting in full auto, along with deciding other variables such as white balance, contrast, color saturation, sharpening, etc. Ultimately it is determined by the writers or the camera's firmware. Some systems are more sophisticated than others and may use context awareness to compare the scene with a database stored in the camera's memory. A predetermined list of settings attached to a profile in the database are then selected when the current conditions match one of those stored profiles.
Having said that, there are some common traits you see shared by many cameras. Most automatic profiles will try to avoid shutter speeds slower than one of several variations of the 1/focal length rule. They typically try to stay in the middle of the road in terms of aperture unless the target shutter speed pushes it further open. They generally try to use the lowest ISO possible and still meet the target shutter speed.
Auto Mode is usually written to cover as wide a set of possible scenarios and conditions as is possible. Cameras with several specialized auto profiles known as Scene Modes will use different priorities and goals for shutter speed, aperture, contrast, etc. depending on which scenario the user has selected. Again, different camera models have various different Scene Modes. For example, Sports Mode will place the emphasis on a fast shutter speed. Portrait Mode, on the other hand, will place the emphasis on a wide aperture and color balance that makes skin tones look their best. Each Scene Mode will apply a set of rules written by the camera's designers based on best practices for that particular type of scene.
Most inexpensive compact cameras that are often referred to as point-and-shoot cameras have such small sensor chips that the focal lengths used to get angles of view in the wide angle to normal to short telephoto range are so short that the depth of field is rather wide at almost any aperture the camera is capable of using, and the selection of aperture is based on what works with the target shutter speed and ISO values.