Natural selection is an evolutionary process where organisms that are more adapted to their surroundings are able to survive and reproduce.
Parasites have lost the ability to live on their own. If they did not live in or on a host, they would lose on nutrition and become extinct. A totally harmless parasite would cause its own extinction as it will not be able to suddenly adapt and live on its own.