Solomon Never Repents, but Kohelet Does
During his reign, Solomon violates Deuteronomy’s law of the king (17:16–17): he acquires wealth, horses, and wives, and God declares that his kingdom will be torn away from his heirs. Yet unlike David, Solomon does not repent. Reading Ecclesiastes as written by Solomon, Rashi portrays the king as losing everything, including his kingdom, during his own lifetime, and not only repenting but also instituting protective measures for the Torah.