In 2 Samuel 12:24-25, it says the Lord sent word through the prophet Nathan to name the son of David and Bathsheba "Jedidiah." So, why was he called "Solomon"?
Here’s the passage in question:
2 Samuel 12:24 Then David comforted Bathsheba his wife, and went in to her and lay with her. So she bore a son, and he called his name Solomon. Now the LORD loved him, 25 and He sent word by the hand of Nathan the prophet: So he called his name Jedidiah, because of the LORD.
It appears that the son of David and Bathsheba was given two names. The first was the name "Solomon" given him by his parents. The second was the name "Jedidiah" given him by the Lord through the mediation of the prophet Nathan.
The second name has spiritual significance. In Hebrew it literally means "Beloved by the LORD." The name was likely given by God as a sign of assurance to David in particular. David had committed adultery with Bathsheba and arranged the murder of her former husband (see 2 Samuel 11). Nathan had confronted David in his sin, saying, "You are the man!" (2 Samuel 12:7). David then repented: "I have sinned against the LORD" (2 Samuel 12:13). Psalm 51 was written by David to express his repentance for his sin. Still, however, there were consequences for David’s actions. The Lord "struck the child that Uriah’s wife bore to David, and it became ill" (2 Samuel 12:15). Eventually, the child died. The name God gave to Solomon through Nathan was, therefore, an expression of assurance to David. This child would be beloved by the Lord. God would preserve this child’s life and even, one day, set him on the throne of Israel.
It is not uncommon in the Bible for the Lord to give a spiritually significant name to a person. Jacob, for example, is given the new name of "Israel" in Genesis 32:28 ("Your name shall no longer be called Jacob but Israel, for you have struggled with God and with men, and have prevailed."). The Lord also gave spiritually significant names to the sons of the prophet Hosea (cf. Hosea 1:4, 6, 9).
2 Samuel 12:25 is the only place in the Bible where Solomon is referred to by the name "Jedidiah," and it is the only place where this word appears in Scripture. "Solomon" obviously became the name by which the child was primarily known.