When you look through the viewfinder your looking through the lens due to a mirror and a prism that sits on top of the camera. When you take a picture the mirror flips out of the way and the image goes straight onto the film/sensor (after the shutter opens for a precise amount of time). There was some interesting tricks with light path to the the autofocus sensor. The prism is great because it un reverses the image.
https://en.m.wikipedia.org/wiki/Digital_single-lens_reflex_c...
Because of digital you can read the sensor and now show the image in a small screen in the viewfinder instead.