How does it? I have a turning hard disk drive in my pc, but I think it would break if I put it on a rocket. Also, what speeds do those things have?
Like it was mentioned in the comments, this would in great extent depend on the evolution of non-volatile storage technology itself. A few things can be taken for granted though with any space exploration mission: Spacecraft active memory, main bus system components and non-volatile memory are built to last with redundant units in place, and all of them physically hardened to meet operational requirements for the environment they'll work in.
What does that mean? Well, let's describe a few examples throughout the history of space exploration to gain some perspective. For example, Voyager probes use what was at the time of their development the cutting edge of digital storage technology. Quoting myself from another answer on how was magnetic tape decay prevented in Voyager 1:
Voyager probes use 8-track Digital Tape Recorders (DTR) to record telemetry and scientific data, and they both have error-correction capabilities, with Voyager 2 having a stronger, more error resistant algorithms in place.
So we see there is redundancy in the way the data is written on the magnetic tape, and the use of error correction algorithms assures data integrity. Moving on to more current times, the Curiosity rover exploring the surface of Mars has a fully redundant set of electronics in two main system buses called A-side and B-Side. It has actually happened to this particular rover, that an unexplained cause resulted in what NASA called the Sol 200 memory anomaly, and the rover was put into safe mode and later switched to using its B-Side while the NASA engineers were working to resolve the problem.
But there is more to it than merely using systems built for redundancy, ensuring data integrity and hardening against environmental conditions like solar radiation, mechanical damage, or even faulty or slowly wearing out and equipment. And no, it is not the use of cutting edge technology and investing a great deal of money into their development. That one should be taken for granted and I probably don't have to throw at you all kinds of examples, Googling for space exploration spin-off technology should produce all kinds of interesting results that we all might be using now everyday as a direct product of throwing a lot of money into space exploration technology.
What I mean is that there are elaborous decision making process involved with designing each and every space exploration mission, establishing operational parameters and matching them with suitable equipment that the mission's success will depend on. This goes the same also for choosing non-volatile storage technology, how many redundant systems are required, and indeed can be afforded. This decision making process that everything depends on is called risk management:
Risk management is the identification, assessment, and prioritization of risks (defined in ISO 31000 as the effect of uncertainty on objectives, whether positive or negative) followed by coordinated and economical application of resources to minimize, monitor, and control the probability and/or impact of unfortunate events or to maximize the realization of opportunities.
Part of risk management is also deciding when some equipment should be active, deactivated, or put in other modes of operation. For example, if the spacecraft or a rover would be predicted (or detected in situ) to experience sudden movement or other contributing factors to the safety of operations and exceed its previously determined operational limits, parts that could potentially be negatively affected by it could be put into safe mode automatically or on remote issued command, hard disks could despin their platters, or be shut down completely to be awaken at a later date.
Such risk management procedures are an integral part of any stage of mission planning, from designing it through to deciding its main objectives. On top of quality assurance, these two management and engineering functions will be working hand in hand to guarantee mission success the best they can, technology and budget permitting. This can be applied to any other industries, and space exploration is no exception.
So, as you can see, it is not merely about what type of hardware is used, but equally importantly how it is used. Often, the parts selected are not on the cutting edge of technology either, but more lasting parts with proven track record will be used instead. That's why you can still read about NASA putting some 5 year old computer processors aboard their spacecraft and you might laugh about having a faster, newer one in your own computer. They have been determined to be sufficient for handling their tasks, and have 5 years of quality assurance and evolution in manufacturing techniques behind them. Something the newer part you might use doesn't.
And same goes for non-volatile storage technology. They would use parts that are generally more robust, environmentally hardened, heavy-duty rated, e.t.c., but any part can fail no matter how well they have proven to work beforehand, so they will also employ redundancy and integrity systems both in hardware, as well as software and the way the data itself is written to ensure its integrity. As there are literally hundreds of individual techniques to assure that, I'll avoid listing them here. But if you have any more specific question, don't hesitate to ask it in a new question.
One thing can be deducted though, that consumer products like the ones you might have in your own computer don't tend to come as hardened, failure resilient as specialized use equipment does. Your hard disk drive (HDD) would still use a lot of technologies that were developed with this mindset described, but they tend to trickle from the edge use case into consumer grade products slowly. Your disk would, for example, employ cyclic redundancy check and other error detection and correction code, some of which might have been developed exclusively for space exploration purposes maybe a few decades back, and have expired patents or don't come with royalties, something consumer grade equipment manufacturers would be avoiding as much as possible to keep the costs down and keep your equipment's selling price cheap and cheerful. I.e. - affordable.
Nowadays it's usually flash memory. Curiosity has 2 GB of flash per redundant computer. Each camera (both Mastcams and the hand lens camera) have 8 GB of flash each. The computers also have a small amount of EEPROM for storing flight software, but those are not used for data.
It is possible to get things like tape drives to survive launch and work in space, and it has been done. However today solid state memory is lower mass and more reliable than other approaches, and can be made radiation tolerant.
Two 545 MB hard drives in a single pressurized enclosure were flown and operated successfully on MSTI-3 in 1996. That is the only example I've found of hard drives operating on a spacecraft, outside of those used inside human-occupied pressure vessels, e.g. inside the ThinkPads on ISS. The STEP-3 spacecraft had one, but that one never made it to space due to a launch failure. Hard drives require air or some gas for the head to literally fly over the hard disk surface. So a hard drive used in space would need its own pressure vessel, or needs to already be hermetically sealed and rated for the vacuum of space.
I doubt that a hard drive will ever be used on a spacecraft again, since the cost benefit of smaller, lighter, and lower power solid-state memory far, far outweighs the cost difference for the same amount of storage.