I always took the heart pieces to be a random game element that is just to be accepted as a game item as opposed to the regular inventory items that can have a bit of story and history to them. Sort of how extra lives are handled in other games. They tend to not at all fit into the game narrative at all and you just ignore it and keep on going.
But then Zelda likes to have these little moments where other NPCs notice the heart containers and not know what they are.
"Oh! You have great taste in things... Isn't it shiny? I found it someplace nearby. To be honest, I have no idea what it's for, but I'll sell it to you for just 1,600 Rupees!" — Beedle
The Item Lady did know all about how common hearts were.
"Lend me your ear for a moment, won't you? You know the street merchant outside? He's selling hearts. Can you believe that? Hearts! I mean, you can just scoop them off the ground with a net. The nerve if that man! Might as well sell leaves off trees! Don't buy them, whatever you do." — Item Seller
So then we could get speculating. It's related to life in some way, life force maybe or life energy. But Nintendo has done that in the past with the force gems. And they took the time to give an explanation for them.
"Force: The sacred power the gods gave to the world. It's the breath of life itself."
"Force Gems can be found all over Hyrule. These gems are the source of the Four Sword's power. They appear after you defeat enemies or cut down grass and bushes."
"It is said to be made of Force Gems of the great spirit, the Ocean King." — Oshus
"As you know, every creature in this world possesses a sacred power. This power is called life force. The Sand of Hours is a physical manifestation of that power. And that is what brought them here." — Oshus
Apparently the Force Gems are some kind of crystallized life energy, and force gems from higher beings like Oshus are more powerful.
Skyward Sword also gave us the Gratitude Crystal
"Oh, right... Silly me. I've gotten ahead of myself! You see, there is an old tale among my monstrous kin that goes as follows... It seems that when humans make other humans happy, the happy humans produce a substance known as a Gratitude Crystal. Gratitude Crystals are quite amazing! Just looking at them and knowing there was such gratitude in the world could turn me from a monster into a human!" — Batreaux
"You got one Gratitude Crystal! These form when a person is so completely overwhelmed with feelings of thankfulness that crystallized gratitude is created. Collect these and show them to Batreaux!"
So Force Gems are the manifestation of life from the gods, graditude crystals are a manifestation of thankfulness,
Now I thought to include these other things because they appear similarly to hearts. Attacking things or cutting grass in some games cause hearts to appear, in other games force gems appear, in SS gratitude crystals just appear all around someone just like them. Strong powers, strong emotions or exceptional magic can take form in the series, even the curse Zant placed on Link took shape as a crystal.
Given what we have explaining other random game elements it would not be too hard to attribute a very similar explanation to the hearts as well. They could very well be another manifestation of life appearing in Hyrule. They certainly represent life, and grant life to the player although that does overlap with the force gems when those appear. They could also be manifest strength, it takes strength and a weapon to cause them to appear either attacking an enemy or cutting grass, sometimes lifting and breaking objects. Pieces of hearts come from a challenge of some kind, or something Link must overcome, and heart containers are given by defeating a great and powerful monster.