It's notoriously hard to lose fat without also losing muscle. That's why bodybuilders bulk well past their target muscle mass before they cut for competition. I agree that you can do a lot to mitigate it through protein intake and resistance training, but you'll almost certainly still lose muscle when you're in caloric deficit, regardless.