I don't understand why pentaprisms are needed to reflect light from the image up through the viewfinder. When I read why it is used, the explanation seems to indicate that it ensures the light coming up is reflected out the viewfinder at 90 degrees. But wouldn't a 45-degree flat mirror accomplish the same thing?
It's important to understand that the image through the lens is inverted in both the lateral (x ↔︎ -x) and vertical (y ↔︎ -y) dimensions. Mathematically, this is the same as a 180° rotation about the z-axis (optical axis).
Thus, the upright image entering the lens, after being refracted and focused, leaves the lens flipped both vertically and horizontally. In order to view the image correctly, some sort of lens or mirror arrangement will have perform an additional left-right and up-down inversion.
A periscope mirror system performs two up-down mirror inverions, leaving the output image the same as the input, meaning a periscope is merely a translation of the image, but does not transform the output image with respect to the input image.
If you used the focusing screen on an older look-down SLR (one without a pentaprism/pentamirror) or TLR camera, such as a Rolleiflex, you'd see an image that is correct top-to-bottom (i.e., the sky is at the top of the image in the focus screen), but is flipped left-right. That is because the 45° reflex mirror that aims the image vertically doesn't transform the image left-right. It essentially undoes the up-down inversion that the lens performs, leaving only the left-right lens inversion.
Thus, the image entering the pentamirror / pentaprism on top of a typical SLR or DSLR is correct top-bottom, when viewed looking down onto the focusing screen. But if you were cut a periscope in half and look down onto the first mirror, the image would be inverted top-bottom (but not left-right).
So the difference between a periscope system, and a reflex mirror in the body plus pentaprism/pentamirror to the viewfinder, is that the pentamirror includes an extra up-down inversion to produce an image that vertically correct, as compared to the periscope system, which expects a correct image entering the periscope system.
Note: In reflex cameras, the pentaprism/mirror is also a roof style mirror, that performs a single left-right inversion in the middle of all the bouncing around. Essentially, one of the reflective faces in the pentaprism/mirror system is actually not a single reflective surface, but an inside corner of a 90° angle that bounces the light laterally, as well as vertically. I guess you could say technically the prism/mirror is no longer penta-faced and more hexa-faced. But I like the existing nomenclature of roof pentaprism to denote that the main light path is inside a 5-sided polygon, with the addition/adjective of the roof feature which accomplishes a secondary goal of fixing the image in the left-right plane.
First you have to swap left/right from the focusing screen (a matte surface since the viewfinder needs to display a 2D image and not a 3D one or you could not figure out whether the camera is focused as your eye could accommodate to the distance). And a pentaprism uses total reflection inside, so in contrast to the lighter pentamirrors it does not lose light for the three reflections inside.