Solomon made an alliance with the king of Egypt by marrying his daughter. He brought her to live in David's City until he had finished building his palace, the Temple, and the wall around Jerusalem.
A temple had not yet been built for the Lord, and so the people were still offering sacrifices at many different altars.
Solomon loved the Lord and followed the instructions of his father David, but he also slaughtered animals and offered them as sacrifices on various altars.
On one occasion he went to Gibeon to offer sacrifices because that was where the most famous altar was. He had offered hundreds of burnt offerings there in the past. 1
References for 1 Kings 3:4
That night the Lord appeared to him in a dream and asked him, "What would you like me to give you?"
Solomon answered, "You always showed great love for my father David, your servant, and he was good, loyal, and honest in his relation with you. And you have continued to show him your great and constant love by giving him a son who today rules in his place.
O Lord God, you have let me succeed my father as king, even though I am very young and don't know how to rule.
Here I am among the people you have chosen to be your own, a people who are so many that they cannot be counted.
So give me the wisdom I need to rule your people with justice and to know the difference between good and evil. Otherwise, how would I ever be able to rule this great people of yours?"
The Lord was pleased that Solomon had asked for this,
and so he said to him, "Because you have asked for the wisdom to rule justly, instead of long life for yourself or riches or the death of your enemies,
I will do what you have asked. I will give you more wisdom and understanding than anyone has ever had before or will ever have again.
I will also give you what you have not asked for: all your life you will have wealth and honor, more than that of any other king.
And if you obey me and keep my laws and commands, as your father David did, I will give you a long life."
Solomon woke up and realized that God had spoken to him in the dream. Then he went to Jerusalem and stood in front of the Lord's Covenant Box and offered burnt offerings and fellowship offerings to the Lord. After that he gave a feast for all his officials.
One day two prostitutes came and presented themselves before King Solomon.
One of them said, "Your Majesty, this woman and I live in the same house, and I gave birth to a baby boy at home while she was there.
Two days after my child was born, she also gave birth to a baby boy. Only the two of us were there in the house - no one else was present.
Then one night she accidentally rolled over on her baby and smothered it.
She got up during the night, took my son from my side while I was asleep, and carried him to her bed; then she put the dead child in my bed.
The next morning, when I woke up and was going to nurse my baby, I saw that it was dead. I looked at it more closely and saw that it was not my child."
But the other woman said, "No! The living child is mine, and the dead one is yours!" The first woman answered back, "No! The dead child is yours, and the living one is mine!" And so they argued before the king.
Then King Solomon said, "Each of you claims that the living child is hers and that the dead child belongs to the other one."
He sent for a sword, and when it was brought,
he said, "Cut the living child in two and give each woman half of it."
The real mother, her heart full of love for her son, said to the king, "Please, Your Majesty, don't kill the child! Give it to her!" But the other woman said, "Don't give it to either of us; go on and cut it in two."
Then Solomon said, "Don't kill the child! Give it to the first woman - she is its real mother."
When the people of Israel heard of Solomon's decision, they were all filled with deep respect for him, because they knew then that God had given him the wisdom to settle disputes fairly.