It sends a very slight electrical current through your legs. That's why you have to stand on a certain location on these scales, so that the current can complete the circuit.
Different types of body tissue have different resistance, and the scale measures those differences to make an estimate of body fat percentage.
And now you can see why these scales can be so inaccurate, especially for men. If you're a guy, the odds are that most of your fat is around your abdomen, and not in your legs. In my case, for example, the scale reads around 19% body fat, but I am really 26%. It's so far off because I have very little fat in my legs.
It's much more accurate for my wife, of course. Women tend to have their fat more evenly distributed than men.
The body fat gadgets they have at the gym, where you hold onto the device, work the same way, except that now the current is going through your arms and chest. For a man, this might be more accurate than a floor scale, since a lot of men who have fat around their abdomen also have it on their chest.