I notice that Psalm 20 is a prayer of the people on behalf of the king about to go into battle. Maybe this was a spontaneous prayer before battle that later became a song to remember that moment.