Did the event mention in Ecclesiastes 9:13 really happen?
It did not happen, it is an allegory.
King Solomon observed that the wise may be poor and those with knowledge may be in disfavor. A basic reason for this is that humans often judge by outward appearances, instead of by the actual state of affairs.(verse Eccl. 9:11)
Wise King Solomon provided - an illustration from his life experience to show this, we read:
Ecclesiastes 9:13-15 NET
13 This is what I also observed about wisdom on earth, and it is a
great burden to me: 14 There was once a small city with a few men in
it, and a mighty king attacked it, besieging[d] it and building
strong[e] siege works against it. 15 However, a poor but wise man
lived in the city, and he could have delivered[g] the city by his
wisdom, but no one listened to that poor man.
The small defenseless city would have fallen in the hands of the "great king" but for the poor man's wisdom proved superior to the king's siege works and his army. The people however instead of feeling grateful to the poor man, they forgot all about him, after the danger had passed.
King Solomon drew the following conclusion from this: Eccl. 9:6 reads
Ecclesiastes 9:16 (NET Bible)
16 So I concluded that wisdom is better than might, but a poor man’s
wisdom is despised; no one ever listens to his advice.
When a man does not have a position of prominence, his words are usually ignored or are given little weight, but when acted on, once the crisis is passed, he is granted no honor.Compare: 1 Cor 1:26-27 and 2:8-11
1 Corinthians 1:26-27 (NET Bible)
26 Think about the circumstances of your call, brothers, and sisters.
Not many were wise by human standards, not many were powerful, not
many were born to a privileged position.[d] 27 But God chose what the
world thinks foolish to shame the wise, and God chose what the world
thinks weak to shame the strong.
Still, wisdom is of great value and certainly is not always disregarded simply because of its having an unpretentious source. Solomon continued:
Ecclesiastes 9:16-17 (NASB)
16 So I said, “Wisdom is better than strength.” But the wisdom of the
poor man is despised and his words are not heeded. 17 The words of the
wise heard in quietness are better than the shouting of a ruler among