It is Clear that King Solomon turned his back on God. If He did, why was he able to write the Book of Proverbs?

“For when Solomon was old, his wives turned away his heart after other gods; and his heart was not true to the Lord his God, as was the heart of his father David.”(1 Kings 11:4)

I have 2 answers about this perspective.

My first answer is:  Most modern biblical scholars would note that in the culture of the ancient world, writings like the wisdom book of Proverbs were collected from various groups and writers, assembled into books and over the course of time came to be attributed to long deceased figures who were legendary from the past.  The stories of King Solomon included accounts of his legendary wisdom (1 Kings 3:28; 4:29-30, 34; 10:23; 11:41). Thus, it was reasonable that a wisdom book like Proverbs eventually became associated with King Solomon.

Moreover, the humans who followed God and led God’s people in both the Old and New Testaments were flawed human beings, even the great King David to whom later tradition attributed the book of Psalms.  Jesus’ own disciples and the apostles were not perfect saints but flawed sinners in need of God’s grace.

The second is: The early Christian theologian Origen, in the preface to his Song of Songs commentary, set the books of Solomon within the story of Solomon’s life: Origen proposed the order Proverbs-Ecclesiastes-Song of Songs.  He explains this in several different ways, but Proverbs comes first because it’s understood as the book of Solomon’s youth, before he went astray; then Ecclesiastes fits in as Solomon’s lament in old age once he has sinned and lost everything. 

Since 1 Kings 11:4 says that Solomon’s heart was turned astray ‘in his old age’ and chapter 5 puts the proverb-writing in the initial flowering of his reign, even before the building of the Temple, this works well with the chronology of the biblical story.