Mathematically, by the requirement that observables with space-like separation must commute. And by the requirement that interactions must be strictly local.
I just want to add that in entanglements, which are the typical nonlocal phenomenon in QM, the locality appears in the form that the total probability that one of the entangled particles produce a certain result, is independent of the settings at the site(s) where is (are) measured the other particles.
Only joint probabilities depend on on the settings of all the particles in the entanglement (two, or three, or n-entangled particles).
Which is, of course, a redefinition of locality in order to make sure that quantum mechanics remain local.
If locality is given a stronger interpretation such as the absence of nonlocal correlations or the absence of nonlocal entities in the theory, then quantum mechanics simply is not local. So the answer would simply be, locality is not preserved in quantum mechanics.
After all, quantum mechanics has two-particle objects described by an entangled wave function, which cannot be broken down into single-particle objects. (A separable object should have its own wave function.) Clearly, if the two particles are flying apart, they cannot be considered a localized object anymore after a long time.
gave a very simple answer to the question "how locality is preserved in QM?". QM is nonlocal.
Two (or more) entangled particles, separated in space from one another, correlate their answers as if the particles were at the same place in space. This correlation is due to the joint amplitudes of probability which are complex. When particles pass through different devices the contributions to a joint amplitude can add contructively or destructively, eventually rendering a joint amplitude null.
We don't have such complex joint amplitudes in the classical mechanics - we have positive joint probabilities.