Dont panic if you do put some weight on, muscle tissue is heavier than fat and people often panic when they start exercising and the scales tell them they are getting ‘fatter’….they arent, they’re losing fatty tissue and building muscle tissue….a good thing.
The second is true, the first isn’t (ok, it is slightly).
“Fat” i.e. fat cells, ‘fat’ and water, has a density of arround 0.995kg/dm3
“muscle” i.e. muscle cells, connective tissue, water, has a density of 1.005kg/dm3.
Overall you should still lose weight at the gym, otherwise you’re just putting on muscle (hopefully anyway) and not loseing the fat. A better/more structured way is to cycle it so that you put on muscle/weight for a few weeks/months, then shed it again, whilst aiming to maintain the muscle.
The first few weeks/month are an anomoly to the trend, you can put on weight as existing muscles addapt by swelling up (‘toneing’ in lady gym speek) with water which aids strength, biger cells can deform more and pull more load, and cussions them from injury. You’re not putting on ‘new’ muscle. Similarly you can not put on weight when you stop going to the gym desite eating the same as you lose the mucle tone (and associated water) but pile on fat to replace the weight.
Yo-Yo gyming is not too disimilar to yo-yo dieting.