I'm new to astronomy and I'm struggling to understand this concept. For example, A 20-cm diameter telescope with a focal length f = 2 meters produces an image of the moon 1.7 cm in diameter. How large is the image of the moon produced by a 5-meter diameter telescope, focal length f = 16.7 meters?
To solve this problem, you can replace the telescope imaging system with a simple pinhole (conceptually) and just draw the rays that pass through the center of the entrance aperture. The Moon is about 29 to 34 arc minutes wide or about 0.0085 to 0.01 radians.
If your telescope has a focal length of 200 cm, then at the focal plane it will be 1.7 to 2.0 cm wide. Since the angles are small you don't need to use trigonometry, just use a small angle approximation:
$$\sin(\theta) \approx\ tan(\theta) \approx \theta$$
when $\theta$ is in radians. So the size of the Moon will be about $\theta F$ where $F$ is the focal length.
In other words, ignore the diameter of the aperture, objective lens or mirror. Just use the pinhole camera model for imaging systems. If you have a multi-element telescope (e.g. Cassegrain or refractor with a Barlow lens) make sure to use the effective focal length of the system at the image plane for $F$. A Cassegrain might have a 40 cm focal length objective but a 120 cm effective focal length for the whole system. You might have a 100 cm focal length refractor but with a 2x Barlow lens you effective focal length will be 200 cm.