As the commenters on the opening post have already pointed out, this mechanism is called 'perspective correction' or in 3D terms 'perspective projection'.
The basic idea is that as things get further away, they get smaller. It's all about trigonometry (calculating triangles).
You can calculate this by assuming that your Field of View is like a pyramid with a square base, where the point is at your eye (or camera) and the pyramid is aligned to the direction you are looking.

If you know the shape of your Field of View and you know the size and location of a point on screen (Near plane), you can extrapolate what size the object should be at a given distance when you scale proportionally.
Remember that objects closer to the Near plane will take up more of the view space and objects further away will take up less space.
Notice how in the picture below, everything gets smaller the further away it is.

The vanishing point is another way to think about it. The vanishing point is the place in the distance where everything converges (the Far plane accommodates this). You can observe this in real-life when you look down a street. If the street were long enough, it would look like a triangle.
You could think of a 2D shape like a circle on the screen and apply the same principle as the view frustum to the object itself, but in reverse. When you extrapolate the circle into a 3D shape, it becomes a cone. The circular base is in your view and the cone points away extending to the vanishing point. If you want to know how big to draw the circle when it is X units away, then you calculate the diameter of the cone at that distance.