First, I should note that other translations make clear that Simeon was specifically taking about a sword piercing someone's soul:
And Simeon blessed them and said to Mary his mother, "Behold, this child is appointed for the fall and rising of many in Israel, and for a sign that is opposed (and a sword will pierce through your own soul also), so that thoughts from many hearts may be revealed."—Luke 2:34-35 (ESV)
The "your" is singular in Greek. The word "soul" is psuche <5590>, which primarily means "the breath of life" and is variously translated in the King James Bible as:
soul 58, life 40, mind 3, heart 1
(The NET Bible lists even more possibilities. There are a whole cluster of Greek words related to the non-material part of people that cause problems in Modern English. We don't have the same metaphysical framework now that people used then.)
Second, the context of Simeon's prophesy is that Jesus will be "a light for revelation to the Gentiles, and for glory to [God's] people Israel." (Luke 2:32 ESV) This is a particular concern for Luke (who was probably the only Gentile Biblical author) and his Gentile audience. The other Gospels don't include this story.
But Simeon shifts to the side effects of Jesus' mission. The essence of these two verses is that you can't make an omelet without breaking a few eggs. Jesus will bring about the ruin of many in Israel (including people like Simeon himself who worshiped in the Temple). We see in the rest of Luke that Jesus did hunt out hypocrisy and reveal many hidden thoughts. Most of Simeon's words are directed toward a large, even cosmic, audience.
Third, the parenthetical remark is directed to Mary. It's possible, I suppose, that Simeon was talking to Jesus via Mary, the way we sometimes talk to infants in their mother's arms. But it would be odd to be talking about metaphorical "hearts" and when shifting to the literal piercing of a physical heart use the word "soul". Further, only John recounts the piercing of Jesus' side after death. If Luke had that event in mind, he would not have wasted this foreshadowing by forgetting to report the prophesy's fulfillment.
More likely, the remark is intended as an explanation of the emotional turmoil we see Mary experience in the rest of Luke 2:
But Mary treasured up all these things, pondering them in her heart.—Luke 2:19 (ESV)
And they did not understand the saying that he spoke to them. And he went down with them and came to Nazareth and was submissive to them. And his mother treasured up all these things in her heart.—Luke 2:50-51 (ESV)
The first three chapters of Luke describe a wide range of people who are waiting for the Messiah (for Jesus) to arrive. Simeon had been waiting all his life to see the "consolation of Israel". When He arrived, he was ready to acknowledge Him and declare His significance. But he also saw that such an upheaval would have disturbing effects on people in Israel, including the mother of the Messiah herself. We can easily imagine her pain at losing her unmarried, brilliant, compassionate son when He was executed for a crime He did not commit. But even in His life, His greater calling brought Mary pain:
Then his mother and his brothers came to him, but they could not reach him because of the crowd. And he was told, "Your mother and your brothers are standing outside, desiring to see you." But he answered them, "My mother and my brothers are those who hear the word of God and do it."—Luke 8:19-21 (ESV)
Perhaps Simeon's prophesy comforted her in times like these.