“Also at play in the betrayal narrative is that Peter had been clinging to a mistaken militant concept of the Messiah (see, e, g., Matt. 16: 21 – 23). This is why Peter appeared so bold while Jesus was working miracles and the crowds were following him, yet revealed himself to be a coward once Jesus was arrested and the crowds turned against him. God’s purpose in having Jesus give the prophecy of Peter’s denial was to reveal to Peter the sinfulness of his own character and help him discover the true, self-sacrificial nature of leadership in the kingdom. The kingdom Jesus ushered into the world advances not by conquering people but by loving, serving, and dying for them (as Jesus was already showing Peter in the garden; see John 18: 10 – 11; cf. Luke 22: 50 – 51). I do not believe it is a coincidence that after the resurrection Peter was made to affirm three times his love for Christ and that Jesus then uttered another prophecy over him. Far from denying Christ, Peter was now ready to follow Jesus to the point of dying just as he died (see John 21: 15 – 19).”
source: Gregory Boyd, Divine Foreknowledge: Four Views, as quoted from “Boyd on Peter” (godisopen).