You can build muscle at a calorie deficit, but not when you’re in starvation mode. Being at a deficit is fine if you’re in weight loss mode, as long as your body is getting adequate nutrition to sustain your activity level (and plenty of protein to rebuild your muscle). Creating too large of a deficit can be troublesome - it signals your body to store fat for energy instead of using it. This happens when we over-restrict or under-consume. All the body knows is that it’s not getting enough, and doesn’t know if and when it’ll get adequate amounts of energy. It slows down other body processes to compensate, and signals hormones to hold on to fat. Muscle, however, is expendable. If it needs to choose between using life sustaining fat, and muscle for energy, muscle wins.
If you notice a drop in performance (suddenly you can’t keep up, can’t lift heavy, or should be improving but are not), a decrease in overall energy, an ammonia smell after a tough workout or are staying sore longer than usual, it may be a sign you’re not eating enough to support your muscle growth. As we get closer to our weight goals, the calorie deficit should be smaller (meaning you can boost your calories a bit to keep your metabolism up, but keep them clean) and more emphasis should be put on food quality, and strength training. Too much cardio when we’re already eating at a deficit can burn away muscle you’re trying to build: muscle that’s the difference for overall fat loss. Eat clean, drink loads of water, but pay attention to signs that you may need to boost your calories.
Too much cardio without proper nutrition can burn away muscle. If your focus is building muscle and changing your body composition, your focus should be strength training and intervals - not cardio. It’s not all about exercise. For muscle growth you need to eat enough in general, and focus heavily on the protein.