Some of the following might cause a "Duh!" response, but are important to understanding. I'll try to keep those facts to a minimum.
What do you mean by ‘to preserve longevity of the hardware’? Am I damaging my iPhone by filling up all its storage?
Not damaging per se, more of not allowing the device to operate its effectively as designed -- probably not enough to notice within the product's typical, preferred lifespan though.
en.wikipedia.org
Wear leveling attempts to work around [the limited number of erase cycles before becoming unreliable] limitations by arranging data so that erasures and re-writes are distributed evenly across the medium. In this way, no single erase block prematurely fails due to a high concentration of write cycles.
As a drive contains more data, that is, less open blocks, it is forced to re-use the same portion of blocks when adding new data. This limited space essentially prevents full wear leveling.
-----
The >=20% (or so) free space suggestion has two reasons.
• HDDs have spinning discs, blocks/sectors placed in rings with an actuating arm that moves the read-write head over these rings as needed. The outer rings are, obviously, larger, thus hold more data, more files and/or larger files. Because of this, the read/write head shouldn't need to move as often -- especially if there's no gaps or file fragmentation. As the drive is filled, it is forced to use smaller and smaller rings, only able to accommodate small files or file fragments thus forcing the drive to seek out all of the data from multiple areas of the discs.
• When a drive is empty, it can probably place data anywhere it wants without needing to separate, fragment, files and other data. As files are written and erased, gaps appear. At first, this isn't a problem because there's plenty of other space and no need to cram data in these gaps. However, as more data is added, eventually, the only thing left are the gaps. To fix or reduce the problem, defragmentation was an added option, telling the OS to rearrange the file data the best it could to make data seamless. One of the exceptions would be, for example, a NAS used for movies and music storage because data isn't added, deleted, or modified often -- basically, what
@rui no onna mentioned and was highlighting in regards to the 20% free space argument being an absolute guideline.
-----
When you think of performance, you primarily relate it to the amount of RAM, right? RAM is important, providing a temporary, very high-speed storage medium that can keep up with high-speed processors. However, offering that speed means sacrificing capacity. Sometimes, not everything can be stored in RAM. In such cases, how do we compromise most effectively, efficiently? Overflows can be placed on SSDs, HDDs, and other persistent storage media, although, they don't offer as much speed. So, slower but still functions. Not ideal but probably acceptable. What if there is plenty of RAM? Does that mean things will always be fast? Not absolutely, but we can try to make that happen. Even if there are plenty of open RAM blocks, iOS and many other operating systems still utilize virtual memory, a.k.a. paging. The OS will move infrequent and low-priority data to the SSD, etc because it shouldn't be a hinderance, plus creates more free RAM for future needs. Of course, this does equate to less free space on your persistent storage media as well as relies on its performance. Additionally, the system is perfect. Sometimes, data priority is wrongfully marked or misgauged or files that haven't been used for awhile are now extremely active, either remaining on the lower performance media or temporary unavailable as it is copied back to RAM.