The simple process for gaining weight is to eat in a calorie surplus, i.e., eating more calories than you burn. But gaining muscle mass not only depends on a calorie surplus, but it also depends on what you are consuming as a surplus.
If you are consuming junk such as pizza, doughnuts, etc. to fulfill your calorie intake, then it would just increase your body fat. If you want to gain muscle mass, the calories should come from high-quality nutrients such as protein, good carbs, good fats, and micronutrients.