You discover a strange statue in the Royal Hidden Passage and have to make a deal.
Quest Location
During the quest Who Goes There?, talk to the statue to start this quest.
Make a Trade
Talk to the statue and you can ask it to give back the heart container, or you can choose to get a stamina upgrade instead. From now on, you can sell a heart container or stamina upgrade for 100 rupees, and buy one for 120 rupees. This means that you can convert your hearts to stamina upgrades and vice versa for 20 rupees.