But why do photos of patch panels show, for example, 16 patched LAN cables plugged in at the back, but only, for example, 5 LAN cables in the switch ports?
In your example, apparently only five of sixteen potential endpoints are actually used, i.e. only five of the sixteen sockets have users.
Assuming I have a 24-port patch panel, then I wouldn't need a 24-port switch, right?
The number of ports on the patch panel is always greater than or equal to those on the switches in general, and certainly greater than the PoE-powered switch ports. If an office has four corners but only three desks, only three workers use their computers, but the fourth corner is also wired, and this cabling at the server room end is not just thrown somewhere. Therefore, temporarily unused ports on the panel are the rule. A switch is an electronic "Fräulein vom Amt" and serves all available workplaces - so none are held in reserve. And injectors for PoE are sometimes only available on part of a switch’s ports because not every endpoint requires PoE. Power over Ethernet (meaning the modulation of power supply for device operation onto the line used for data exchange) is mainly needed where, in an office telephone system, a separate power adapter cable should not be used for every IP phone. The plug-in power supplies are comparably cheap s**t and are also often avoided fire hazards.
The patch panel is nothing other than the orderly collection of cable ends.
A plug-terminated orderly collection, to be more precise.
This can prevent someone from quickly plugging into the network in an empty office or public space.
The system administrator prevents this through permissions, which are by no means related to the use of the sockets.