It's great how conscious you are about your health! It is possible to lose weight while gaining muscle mass. As long as you are consistently eating adequate nutrition and exercise regularly and moderately, there should be nothing to be worried about. There are instances where weight loss is unexpected and unexplainable, and in those cases, I would recommend paying a visit to your doctor to ensure that all your blood markers and levels are on par. Just to be safe, please check with your doctor.