Not necessarily. While it's technically possible to gain muscle while losing weight, it's generally not recommended as it can put unnecessarily stress on your body/lifestyle, as well as unrealistic expectations. The most important thing for losing weight is calories out > calories in.