In some instances this works. In others, a plateau of muscle gain is reached while still under what later proves within reach for the same person on a different plan.
It tends to be better for a beginner than someone who's already made substantial muscle progress.
An instance where it can work for a more advanced lifter is in short periods of time when there's a stimulus or change of some sort that's really making a difference. Sometimes a major change in training or nutrition can result in some combined muscle gain and fat loss in the same time frame of a few weeks or a couple of months, without making any effort to change calories. But it's more a happy outcome than usually the best way to plan for either fat loss or muscle gain.