Exercise is important for building and maintaining lean muscle mass. If your goal for weight gain is to modify your body composition by increasing lean muscle mass and reducing body fat, then exercise should be part of your weight gain plan.
However, keep in mind that working out contributes to a calorie deficit and it's important to consume enough calories to support your weight goals.