If I want to lose weight, should I first gain muscle?
If your main goal is to lose weight, your focus should be on nutrition rather than the types of exercise you are doing. You will not be able to out exercise a diet that isn't aimed at your main goal, meaning, if you're in a caloric surplus and you're trying to lose weight you're pretty likely to fail.
With that being said, you are right about the increase in muscle. As you increase the amount of muscle you have, you will see an increase in metabolic rate. Though you should keep in mind that this takes time and shouldn't be relied upon to lose weight. Again, your focus should be about controlling the amount of calories you are consuming first.
As Kevin stated, it isn't an either or option here. You can do both aerobic training, along with anaerobic training. You might also be interested to know that most physiologist now recommend doing a mix of both. Typically you see recommendations of 3-5 days of cardiovascular training at a moderate to heavy intensity, while completing 2 or 3 days of resistance training.