In order to build muscle, your muscles need three things: exertion, rest, and fuel. [1]
The exertion and rest portions come from a proper workout and rest routine. The point of concern for your question is the fuel aspect.
A calorie surplus is recommended for muscle growth (hypertrophy) as most individuals don't eat enough to build the muscle mass they're looking for. However, the additional energy input doesn't need to come from a calorie surplus. If your body has energy stored in fat it can use that energy to build muscle mass as well, meaning, you can also build muscle in a caloric deficit if the circumstances are appropriate. [2]
This doesn't mean fat magically turns into muscle. It just means the energy is available.
The process works best in a slight caloric deficit (500 to 750) with high protein intake. Research has shown that 1.4 - 2 g of protein/kg body weight (0.6-0.9 g/lb) is ideal for muscle growth. [3] Further research has shown that 2.3 to 3.1 g of protein/kg of lean mass (1-1.4 g/lb lean mass) in a hypocaloric diet is required to maximize lean muscle retention. [4]
Will muscle just build a lot slower while I'm trying to lean down?
The short answer is yes.
While it is not impossible, building muscle and losing weight at the same time should be a slow and steady process. You're attempting to push your body into an energy-intensive change (build muscle) while restricting the energy available (calorie deficit).
Anecdote: In the first half of this year I was working out with a protein intake of 1 g/lb but trying to lose some excess fat by doing a calorie deficit. I definitely saw strength increase, lost 10 pounds, but I can't say I noticed much in terms of muscle growth. In the second half (roughly July to now) I reevaluated my goals and priorities. I kept my protein intake the same but upped my calorie intake to a surplus. My strength has increased more, I am noticing muscular improvements, however, some stomach fat has returned. This time around though it doesn't bother me as much, I know I can lose it.