"'During the night this woman's son dies because she lay on him. So she got up in the middle of the night and took my son from my side while I your servant was asleep. She put him by her breast and put her dead son by my breast. The next morning, I got up to nurse my son - and he was dead! But when I looked at him closely in the morning light, I saw that it wasn't the son I had borne.' The other woman said, 'No! The living one is my son; the dead one is yours.' But the first one insisted, 'No! The dead one is yours; the living one is mine.' And so they argued before the king." NIV translation
Each woman claimed the living child as her own. We must remember that this was before the age of paternity tests and DNA analysis. It can be very difficult to look at a baby and say that it belongs to a certain person.
"The king said, 'This one says, "My son is alive and your son is dead," while that one says, "No! Your son is dead and mine is alive." 'Then the king said, 'Bring me a sword.' So they brought a sword for the king. He then gave the order: 'Cut the living child in two and give half to one and half to the other.' The woman whose son was alive was filled with compassion for her son and said to the king, 'Please, my lord, give her the living baby! Don't kill him!' But the other said, 'Neither I nor you shall have him. Cut him in two!'" NIV translation
Using the wisdom that God had granted him, Solomon proposed cutting the child in half to divide it among the two women. The one lady begged him to give it to the other while the other lady was happy knowing that, if she couldn't have him, then, the other lady couldn't either. They had no idea that the king was just testing them but they knew that he had the authority to do what he said.
"Then the king gave his ruling: Give the living baby to the first woman. Do not kill him; she is his mother.' When all Israel heard the verdict the king had given, they held the king in awe, because they saw that he had wisdom from God to administer justice." NIV translation
God had given the king the wisdom to know that a loving mother would do whatever she had to do in order to save the child. When word of the ruling got out, everyone was amazed and knew that it was from God.
This is a big contrast to our judicial systems today where people are qualified to judge based on some college degree and not whether they have wisdom from God.