out of universe
FWIW, I figured it was magnetic from remembering Data remove his to use as a bet in a poker game when he as stranded in the past. I duplicated it by using Gaf Tape to attach the metal plate to the inside of the ordinary cloth costume. Just clasping it with the plate on the inside (magnet molded into the resin prop) would allow it to fall out if the badge were removed in a scene, or accidently bumped.
(Note: in that scene it did not stick to the table. It appears to home in to the right spot when attached.)
However, mine twists along an axis directly over the magnet. The series production must have used multiple magnets or a rough prickly texture on the backside which was never seen. More likely used pins when the badge was not needed to be removed or attached during the scene: at least after season 2 when shirts were made of normal cloth and were not form-fitting. I never determined how it was done on the spandix uniform: pins or double-stick tape would not work well or even damage the material. So I suppose a thin metal plate that fit (only) behind the badge, and was anti-swivil, was designed to go with the original S1/S2 uniforms. Adding a little tape would permit the apply-or-remove actions we saw.
in universe + hard SF
Rather than a crude ferromagnetic plate as a bulk piece, a patch meant to accept the badge would be fabricated into the cloth. It would be no more mysterious to them than post-it notes are to us.
One time I marvelled at a label attached to a non-stick pan. It was quite strong to peel off but only barely tacky to feel or against ordinary surfaces. I thought the sticky had been spent, and was surprized that it still stuck strongly to teflon.
Clearly you can design to materials to be sticky (only) to each other. Patches of A in an aligned grid would allow B to stick in the intended spot and easily be positioned straight.
Using "molecules" (purpose-specific adhesive) would better fit the stated references, and has advangages advantages over magnets around equipment and in strange conditions.