The selection of the yarn weight has much to do with the intended knitting project.
If you are wanting a chunky sweater, then it stands to reason that you would choose a heavier weight of yarn. Equally, looking for something more elegant and lacy, then you would likely choose a lighter weight of yarn.
The below table gives you the weights and needle sizes for different yarns and the “suggested” usages. Of course, rules are made to be broken so feel free to experiment.