What is an atomic force microscope (AFM) in the first place?
An AFM uses a very sharp tip to "probe" around the surface of an object. As it gets closer to or further away from the surface, tiny changes in force are observed from van der Waals or similar "atomic" forces. A computer can stitch together a grid of individual passes over the surface to give an overall image. The size of the tip can allow imaging in the 0.1 - 1 nanometer range. On MIDAS, the probes were mounted to the moving microscope stage through a piezo crystal, which allowed both movement through an applied voltage, and measuring of the tip force through an induced voltage.
Sample AFM Probe. Note the scale at the bottom of the image (1)
How did they design the AFM to survive space?
As @uhoh has commented, Earth-based AFMs are not known for their robustness, although they are generally smaller machines compared to other methods, such as Scanning Electron Microscopy. This is because they rely on an extremely sharp tip , which can be damaged through actual contact with a surface rather than just floating near it. The safety of the tip was obviously a concern, both from launch stresses and operation. For operation, 16 tips were included, with the ability to switch out the tips automatically (2). Safety during launch was fairly simple, consisting of just locking everything in place where the tips couldn't come into contact with anything. Vibrations of the spacecraft during AFM operation were handled by a mechanical damping system, which nullified vibrations with frequencies above ~5 Hz (2). Additional resiliency was provided by using the same piezo crystal for vibration and for measurement, reducing the AFM complexity and avoiding the need for separate measurement equipment close to the tip.
How did they capture and position dust (from the comet, and in general)?
The capturing and imaging was a multi-step process. First, a "horn" on the outside of the spacecraft was used to capture and guide dust towards a "shutter". This shutter opened to allow an "exposure" of one of 64 sections on a wheel, which had been specially coated with solgel. The 14 nm-thick layer of solgel allowed particles to slightly embed themselves in the surface upon impact, resulting in a overall very flat, slightly "sticky" surface.
Calibration after launch was performed by imaging an unexposed section of the wheel, which gave a very flat reference surface. Any damage to the probes could thus be detected and corrected for. After an exposure, the wheel could be rotated and then translated up to 30mm sideways to select the correct tip for use. The microscope then slowly brings the tips down to the correct height for imaging, and rasters them across the surface.
(3, see this image)
Image of MIDAS: The horn is on the left, the sample wheel is in the middle, and I believe the actual microscope tips are part of the black and white bar connected to the brown strip labeled "F15". Image courtesy Mark Bentley @ Institut für Weltraumforschung
If you have further interest, I can strongly recommend the paper found by @astrosnapper, (2) which goes into greater detail about the instrument itself. Interestingly, the whole instrument was only 8kg, and consumed only 7.4W (4).
It is also of note that this is not the only AFM in space, the Mars Phoenix lander also carried an AFM, which actually went into operation before MIDAS, due to the length of time needed to reach the comet vs. Mars. (link)