They work by sending a very mild electrical current through your body, and seeing how long it takes to get the whole way around. Different types of tissues conduct electricity at different speeds, so the scales then - yes - make assumptions about the quantities of different tissue types, including fat.
So for example, water is a good conductor or electricity, as is fat (while muscle is a bad conductor - it takes electricity longer to travel through it). If you're carrying a lot of water, then the machine won't be able to tell the difference between the water and the fat. Although if you're dehydrated, that also affects the results, so having a glass of water half an hour before using will usually increase the accuracy.
Men and women will typically have different proportions of different types of tissues, so the scales make assumptions based on our gender about those proportions. And the ageing process affects our tissues - e.g. older women typically have less muscle, and the muscles become softer when we're over 50 - so assumptions based on age are also used to understand why the electricity is travelling at the speed it is.
They will never therefore be 100% accurate, but few of us really need to know completely accurately - a good estimate is fine.
The most accurate way to measure body fat is with calipers, but personally I'm never going to do that so body fat at-home scales tell me if I'm going up or down & need to do something about it.
Sorry that wasn't a very light hearted answer...