Let me (Wikipedia) enlighten you:
The practice of ransoming prisoners has been around for a long time, but it became a common and important part of medieval warfare and diplomacy. In primitive times, captured warriors were often enslaved or killed, but during the Middle Ages, ransoming prisoners became beneficial for captors. Capturing a wealthy or high-ranking prisoner could be a financial opportunity, and keeping prisoners required upkeep costs. For example, knights who were vassals of a lord were expected to pay for their lord's release if he was captured. In the late Middle Ages, family and friends, as well as the lord's estate, might also contribute to the ransom.
Ransom also contributed to the development of heraldry, which allowed knights to advertise their identities and ransom value, making them less likely to be killed immediately.