The phrase likely has its roots in English literature and can be traced back several centuries. Historically, the heart was thought to be the seat of emotions, including love and jealousy. The phrase originally may have carried a more sincere, emotional tone, suggesting that the individual should quite literally "consume" their heart—an essential part of themselves—because of their unfulfilled desires or sorrow.
Today it is an idiomatic phrase that is commonly used in a jocular or sarcastic manner to indicate that someone should feel envious or jealous of the speaker's accomplishments, attributes, or situation. For example, if someone makes a particularly good basketball shot, they might say to their friends, "Eat your heart out, Michael Jordan!" to imply that even the basketball legend should be envious of the shot. The phrase is a way to show off something in a cheeky or boastful manner, often without any real malice or arrogance intended.