Don't confuse formulas meant to be used with refractive optics (i.e., lenses) with projection mapping functions (such as the pinhole projection model). That is, the Wikipedia formula you found has nothing to do with your question.
The thin lens formula only applies for refractive lenses, such as glass elements that bend light. The thin lens formula is really just an idealization of a refractive element described by the lensmaker's equation with negligible thickness of the lens (hence the name, thin lens). Concepts such as depth of field are defined and derived from applications of the thin lens formula.
The pinhole model is a projection model. That is, it describes the mapping from the field of view to the image plane. The pinhole model is a 1:1 mapping — every ray entering the pinhole leaves the pinhole at the same angle, for the entire field of view. Many refractive lenses (i.e., subject more-or-less to the thin lens model) have a pinhole projection mapping function. But not all. Wide angle lenses, and especially fisheye lenses, do not follow the pinhole projection formula.
This is easy to understand in the degenerate case: how can a circular fisheye lens with a 180° angle of view in all directions project onto the camera's image plane, unless there is some sort of angular distortion such that the further away from the optical axis the subject is, the more the image rays are bent to project within a confined cone? That's impossible to do with a pinhole projection model. But it's not difficult with a series of concave lenses in front of the lens to bend the incoming light into the "funnel" of the lens's collection area and project it onto the camera's image plane.
It appears your first image came from a slide deck PDF (or one of it many copies online) for a senior-level undergraduate class in computer science. Unfortunately, the slide deck could have used one more very simple image to demonstrate the pinhole projection model:
Pinhole camera model, from Wikipedia Commons. Public domain.
Here is easy to see the relation between the real-word subject (tree), and its image formation inside the pinhole camera. The depth of the pinhole camera is the focal length, ƒ. The two red rays, the bounding rays of the subject tree, enter the pinhole, and leave (continue towards the image plane) at the same angle. Thus, simple similar-triangle geometry describes the pinhole projection formula.
So, the mathematical reason the image plane is at Z = ƒ is because it is the definition of the pinhole projection model. That is, Z = ƒ is idempotent in the pinhole projection model.