Common sense will tell you, it is possible. Why is because you are measuring a Percentage of fat. So as you become more muscular, even if your fat levels stay exactly the same, the percentage of your weight that is fat will decrease...so for example....let's say someone weighs 200 lbs and has 20% bodyfat. That means they have 40 lbs of fat and 160 lbs of non-fat weight. Let's say they then gain 5 lbs of muscle. Now they weight 205 lbs, have the same 40 lbs of fat but now have 165 lbs of non-fat body mass. Their fat percentage drops to 19.5%.
Similarly, if you are losing weight, it's mostly going to be from fat at first---so lets say you lose 10 lbs and 7 lbs is fat, 3 lbs is non-fat weight, just as an example. You now weigh 190 lbs with 33 lbs of fat. SO now your body fat percentage is 17.3%. In fact you didn't gain non-fat body weight, you actually lost some, however, you lost a much higher percentage of that weight in fat and so your percentage of overall fat your body has is now lower.
I hope that helps clear up the confusion.
As to the original question of building muscle while doing this, again the only chance you have is if you lift very heavy weights to force your body to hold onto as much muscle as possible and eat extra protein to make sure i has enough to rebuild the muscle tissue with.
True, but the OP was talking about losing fat, not necessarily bodyfat %. Furthermore for intermediate or advanced lifters you cannot gain muscle mass while being in a caloric deficit, which is required for fat loss.
It is true that by adding muscle you will reduce your bodyfat%. However, the reality is that when you work the math, the impact of gaining muscle mass is minuscule approaching irrelevant, especially compared to the impact of actually losing fat through diet/activity. In your first example, it would take 2.5 months for a brand new gym beginner to gain 5 lbs of pure muscle. 2.5 months to lose .5% bodyfat is incredibly slow. If you are talking about a more advanced lifter then there is no way that they will be able to gain 5 lbs of muscle without putting on some pounds of fat as well. This, in turn, will likely increase the bodyfat% rather than decrease it.
For advanced lifters this will result in simply spinning their wheels. The OP wasn't very specific in their post. The thread title mentions gaining muscle/losing fat at the same time whereas his actual question was about losing fat while maintaining muscle mass and getting stronger/leaner.
By losing fat yes you will get leaner, so long as you diet properly and don't lose the muscle as well. Strength is a far more complex system. It is far more neural based than simply mass. I always cut my volume back when I diet and as a result I tend to find slight increases in strength in subsequent sets as my muscles are less exhausted from less sets, however this is always an initial reaction and doesn't continue after the first week of changes.
Unless you are a rank beginner to the weightroom, its better to stick to either gaining muscle or losing fat, but not both at the same time.