Unfortunately the origins of this idiom aren't super clear. What we do know is that people say an object will "cost an arm and a leg" to imply it's very expensive, and that the phrase likely originated in America around the 1930's, and started being used in print in the 1950s.
Other than that, here are some guesses as to its origin:
1. Painters would base their portrait-prices on how many limbs needed to be painted, and would charge extra for arms and legs.
2. Many soldiers who fought in World War I lost limbs, making life extremely difficult (and therefore costly).
3. Early 20th-century factories were very dangerous, but the jobs were worth it, even if a worker lost a leg or an arm in the process, because the work would make money.
4. Some gruesome forms of capital punishment were used for a period of history, where someone by law could get their arm cut off for stealing, have their legs crushed, etc. So the criminal act could literally cost a person a limb.
5. It's an extension of the phrase "to give one's right arm for". Since that's usually the dominant stronger arm, if the speaker is willing to sacrifice it, the object in question must be very valuable.
6. It came from the phrase "if it costs a leg!" used by desperadoes seeking revenge or criminals involved in illegal activity. It would be worth it for them to do these acts even if it "cost them a leg" along the way.
7. It came from the army phrase "to chance one's arm", used to describe a risky situation that could come with great reward. In this scenario, the "arm" the soldier would lose upon failing would be a rank, and thus a stripe from his arm's sleeve.
Anything I missed?