It is typically called "lens compression," where things farther away appear nearer to the subject/closer together. And the opposite of this is typically called "lens distortion," where something closer to the camera appears larger than it should... like someone's nose in a portrait.
Neither effect actually has anything to do with the lens, and it is not compression nor distortion; it is simply perspective. And it is caused by differences in relative distances.
For example; start with a 50mm lens, a subject at 10ft, and the background at 40ft (30ft behind the subject). And then you switch to a 200mm lens. To keep the subject the same size in the frame w/ the 200mm lens you have to move back 4x the distance to 40ft (+30ft); which negates the increased magnification at the subject distance.
But you did not move back 4x the distance to the background; you are only 70ft from it, when 160ft (4x40) is required to negate the increased magnification of the 200mm lens at the background distance... more than 50% of the increased magnification remains, so the background details appear larger and closer to the subject.
At any given distance/camera position you can change the lens/magnification and the perspective will not change; because the relative distances do not change... the change in magnification affects foreground/subject/background equally.
Neither effect actually has anything to do with taking a picture... it is the difference between trying to judge the space between two parked cars a block away, as compared to judging the space between the cars when you are much closer to them.