Like people have said, when looking at individual devices, it's hard to say. Even if you can expect 99% of the drives to last 5 years, there's no guarantee that the drive you bought wouldn't be more marginal or wouldn't fail early or last longer. It's all viewed from a larger population. One thing you can probably expect for really anything is that putting stressors on a product it wasn't intended to handle will likely reduce the reliability but even then it's hard to say. Consumer storage devices are generally spec'd to last about 3 years. I wouldn't be surprised for an HDD to last longer, but I wouldn't count on it.
Now if you want some more details on what can affect a drive, you're somewhat correct in thinking that the mechanical nature of HDDs plays a factor.
Workload is one of the biggest factors obviously. This doesn't necessarily mean amount of data transferred, but rather more on how the drive is accessed. For some examples, lots of random operations and seeks will mean more movement of the mechanical arm whereas if the workload is mostly sequential, then you can crank through a bunch of data with minimal movement. Depending on the design of the drive, lots of spindown standbys can also put more wear on the motor.
Environmental can play a big part as well. High humidity, high altitude, and excessive temperature can all be different stress factors on an HDD. High external shock like dropping a drive is of course well known to be problematic, but vibration can also be a factor depending on the severity and maybe even frequency.
Now for most normal use cases though, I would still expect an HDD to outlast a similar class SSD. While SSDs are not mechanical, it doesn't make them any less susceptible to wear.
On the workload side, due to simple electrical physics, there is a fairly hard defined limit on how much data can be written to each NAND block of an SSD. This is why SSD life is often reported in TBW (terabytes written).
On the environmental side, while humidity, altitude, shock, and vibration are not as big of a factor, SSDs are much much more susceptible to heat. This is again, simply due to the characteristics of a semiconductor type device. What makes the issue potentially worse is that SSDs generate more heat during operation than a HDD, especially for faster NVMe devices. So they can pretty much cook themselves without sufficient cooling.