A bit more of a tech explanation.
You get energy from already existing fat which and sugar from what you eat.
You'd usually have to break fat to create ATP to energize the body even if you eat quite a bit of sugar, meanings, some of the food you eat is used as immediate energy, some is used to store energy (as new fat).
A while after you eat, your sugar levels from food drop and your body needs to break fat cells again to energize.
So you can lose weight and change where the fat is at the same time!
As for muscles, testosterone is what makes muscles bulk. You can work out and not bulk if you are on hormones.