When is it possible?
As with any good rule, there are exceptions to this one. We'll name three: if you have a lot of overweight, if you are a beginner athlete, or if you have had a long training break, it is possible to build muscle while losing fat.
Here's how it works: when you start exercising for the first time (in a long time), you build muscle mass more quickly. This can mean that you lose very little weight in the first few weeks, while you're actually losing a lot of fat and building muscle. If your mirror image shows you're doing well but the scale doesn't budge at first, that could be perfectly fine.
For your body, exercise feels completely new. Your unsuspecting muscles suddenly get a wake-up call, causing them to grow quickly. These are also called "newbie gains" (1), and you can even get them while following a calorie-restricted diet.
An additional advantage of building muscle is that you also burn more energy. Protein synthesis, which promotes muscle growth in cells, is one of the most energy-consuming processes (2). In the long run, your new muscles will therefore also support your fat burning.