When you start gymming, you initially start gaining weight because of an increase in the muscle mass. Hence the weight gain. However this gain is more in terms of the body getting toned and not becoming overweight.
You start losing fat mass eventually which takes about a month or two depending person to person and starts balancing the muscle gain. Weight that is lost quickly is neither fat nor muscle, it's basically the water you lose which gets accumulated faster when you leave exercise.
Next Steps
You can contact me on direct consult for more detailed reasons to gain a better understanding of how the body responds to changes in diet and lifestyle.