There is no contradiction here.
We must frame these verses by Heb 5:7 and 8
During the days of Jesus' life on earth, he offered up prayers and petitions with fervent cries and tears to the one who could save him from death, and he was heard because of his reverent submission.
Although He was a Son, He learned obedience from the things which He suffered. 9And having been perfected, He became the source of eternal salvation for all those who obey Him
Jesus had his own will. John 6:38, 5:30 His will was always brought into subjection to God - the time before the cross was the most extreme - as we would expect.
It was this constant battle that required Jesus total dependence on his Father's provision through the spirit. This is what makes Jesus and His Father one - that they are united in purpose by the same spirit. Even though, Jesus had differing desires (own will) he was able to pursue God's will and purposes to the very bitter, yet triumphant end.
Jesus had just been explaining about the priorities of life, (John 12:25)
he one who loves his life loses it, and the one who hates his life in this world will keep it to eternal life.
Yet he was struggling to be the prime example of this on his own. On his own, he would have failed and died. If Jesus put his will before the Father's (sinned) he would not be raised - this is what Heb 5:7 tells us - mentioned earlier.
Heb 5:7 is not talking about death on the cross. It is referring to the constant battle Jesus faced surrendering his will to the Father throughout his earthly mission.
His mission centred around V8 being prepared to be the Lamb - "if you are willing, take this cup from me" This is part of the great suffering being brought to a climax and Jesus total obedience to endure through crucifixion and death. Heb 5:8
Some mention Jesus being forsaken on the cross. This is completely untrue when we understand what Jesus was talking about.
Jesus was quoting the beginning of Ps 22. He knew that all the Jews knew these Psalms well - perfectly!
Much of the Psalm points to What Jesus experienced.
A disgrace of mankind and despised by the people.
All who see me deride me;
You have been my God from my mother’s womb
I am poured out like water,
My heart is like wax;
It is melted within me.
My strength is dried up like a piece of pottery,
And my tongue clings to my jaws;
And You lay me in the dust of death.
They pierced my hands and my feet.
They divide my garments among them,
And they cast lots for my clothing.
For the kingdom is the LORD’S
And He rules over the nations.
All the prosperous of the earth will eat and worship,
All those who go down to the dust will kneel before Him,
Even he who cannot keep his soul alive.
31They will come and will declare His righteousness
To a people who will be born, that He has performed it.
What we don't see in our bibles is the better rendition of the last phrase.
Only the Amp seems to show it as follows,
They will come and declare His righteousness To a people yet to be born—that He has done it [and that it is finished].
Thus, Jesus had begun Ps 22 with just 1 line - and then finished with the last line. Everything in between was relevant to the suffering of men - but specifically Jesus, who suffered for all to bring about a hope and trust in the future of God's creation.
Jesus time on the cross and his death was the culminations of the baby born of Mary. Why would the Father abandon or forsake His beloved son at the climax and most glorifying moment? The son who he loved and the son who (obviously) loved Him.
We might think this is possible if Jesus 'became sin' as some passages show.
Cor 5:21 For him who knew no sin he made o be sin on our behalf
'hamartia' (sin) can be translated as ‘sin’ or ‘sin offering’
This is an error to pick one verse which could be translated another way. There are numerous passages showing Jesus to be a sin offering. Of course he was an offering FOR sin - for ALL sin. God doesn't need Jesus to take on sin himself - just the penalty of sin. His death in place of all ours.
1 John 3:5 And you know that He appeared, so that He might take away sins; and in Him there is no sin.
Rom 8:3 God sent His son in the likeness of sinful man to be a sin offering
Heb 9:28 so Christ was sacrificed once to take away the sins of many; and he will appear a second time, not to bear sin, but to bring salvation to those who are waiting for him
Just as every offering, every sacrifice was to cover the sins committed - so to, Jesus covered the sins of all for all time.
No, there is no contradiction when we understand Jesus, the man sent to be the offering for all creation, who struggled with this onerous role but was ably supported to the death by His God and Father - who raised him to be at His right hand and made him heir of all the He had made and gave him authority over all things in heaven and earth.