"God fulfilled David's desires in his old age. As it says in Ecclesiastes 3:11, 'God has made everything beautiful in its time.' Rabbi Tanchuma taught, 'God created the world in its proper time.' This teaches us that the Holy One, blessed be He, created worlds and destroyed them when they were not fit to be created.
He said, 'This is fitting for Me, and this is not fitting for Me.' Rabbi Simon said that it was fitting for Abraham to be created first, before Adam. But God said, 'If I create Abraham first and he fails, there will be no one to fix it. Rather, I will create Adam first, so if he fails, Abraham can come and fix it.'
Another interpretation of 'God has made everything beautiful in its time' is that the three righteous people - Adam, Noah, and Abraham - were the foundation of the world. Everything God did was beautiful in its time. Hot fruits are eaten in the winter, and cold fruits are eaten in the summer. Everything God did in His world, He did beautifully.
David said before God, 'Everything You have made is beautiful, and You have done it with wisdom.' And as it says in Psalm 104:24, 'How great are Your works, O Lord! In wisdom You have made them all.' But the foolishness You created, what pleasure is there in it?
When a man walks in the marketplace and tears his clothes, and children run after him and people laugh at him, is this pleasing to You? God said to him, 'David, you call this foolishness, but one day you will need it.' And Solomon said in Proverbs 13:18, 'He who despises instruction will pay the penalty.' What is the penalty he will pay?
He will be drawn towards it, as it says in Exodus 22:24, 'If you afflict him, he will cry out to Me.' Another interpretation of 'David, you call this foolishness' is that you will suffer and pray for it until it is given to you. David did not stop until he went to Achish's house, as it says in 1 Samuel 21:11, 'David got up and fled that day from Saul.' God said to him, "David, you are going to Achish while yesterday you killed Goliath and his brother, who kept the head of Achish, and his blood has not yet been avenged.
And you are going to him with his sword in your hand. When they saw him, they said, 'Hasn't this guy killed our brothers?' They went to Achish and said to him, 'We will kill the one who killed our brother.' Achish replied, 'He did not kill him in battle, and your brother killed him outside of battle.
And now that he has killed your brother, this is not how we deal with him.' (1 Samuel 17:9) If he is able to fight me and defeat me, then he shall rule over you." They replied, "If that's the case, then step down from your throne and give the kingdom to David." And so it is said, "Is not this David, the servant of Saul the king of Israel?" And we will be his servants.
They were confused with words. At that moment, David was afraid and began to say, "In the day of my fear, I will trust in you." David began to ask and pray, saying, "Master of the universe, answer me at this hour." The Holy One, blessed be He, asked him, "What do you ask?"
David said to Him, "Answer me with that folly that You created, which I read about You. Respond to me." He said to him, "Did I not tell you that 'He who despises the word will be destroyed'?" Since it is so, I give him to you."
In his years, David explained to Abimelech his reasoning, and Abimelech was righteous as Abraham. When David heard this, he was frightened. And so it is said, "And David put these words in his heart." He acted like a madman and changed himself, and he wrote on the doors that Achish the king of Gath owed him 100,000 and his wife 50.
And his daughter and mother were mad, and they shouted and behaved foolishly. Achish said to them, "Do you not know that I am lacking crazy people like you?" At that moment, David was happy that the madness had worked, and out of that joy, he composed this poem. The Holy One, blessed be He, said to him, "David, madness is good."
This is what is written, "I will bless the Lord at all times." And so it is said, "Do everything beautifully in its time." And so it says in the beginning of Genesis, "And God saw all that He had made, and it was very good."