John Piper passionately argues in his 2003 sermon Palm Sunday Tears of Sovereign Mercy that this doesn't contradict the doctrine of foreordination:
There is something not quite right about this objection to Jesus’ sovereignty. He can make praise come from rocks. And so he could do the same from rock-hard hearts in Jerusalem. What’s more, all this rejection and persecution and killing of Jesus is not the failure of Jesus’ plan, but the fulfilment of it.
...
The betrayal, the mockery, the shame, the spit, the flogging, the murder – and so much more – was planned. In other words, the resistance, the rejection, the unbelief and hostility were not a surprise to Jesus. They were, in fact, part of the plan. He says so. This is probably why it says at the end of verse 42, "But now they are hidden from your eyes." Remember what Jesus said about his parables back in Luke 8:10: "To you [disciples] it has been given to know the secrets of the kingdom of God, but for others they are in parables, so that ‘seeing they may not see, and hearing they may not understand.’" God was handing them over to hardness. It was judgment.
We have seen all this in Romans 9. The mercy of God is a sovereign mercy. "I will have mercy on whom I have mercy, and I will have compassion on whom I have compassion" (Romans 9:15). But here is the point I want you to see today: This sovereign Christ weeps over heard-hearted, perishing Jerusalem as they fulfilled his plan. It is unbiblical and wrong to make the tears of mercy a contradiction to the serenity of sovereignty. Jesus was serene in sorrow, and sorrowful in sovereignty. Jesus’ tears are the tears of sovereign mercy.
And therefore his sovereign power is the more admirable and the more beautiful. It’s the harmony of things that seem in tension that makes him glorious: "Merciful and Mighty," as we sing. We admire power more when it is merciful power. And we admire mercy more when it is mighty mercy. And, as I said, my prayer is that as you see his mercy and admire his mercy, you will become like him in his mercy.
But still, why would he be moved to tears over things that he divinely foresaw, and even ordained? It's a valid question. Reformed writers have explained it a few ways.
He wept because he was human
John Calvin's commentary says:
As to those who think it strange that Christ should bewail an evil which he had it in his power to remedy, this difficulty is quickly removed. For as he came down from heaven, that, clothed in human flesh, he might be the witness and minister of the salvation which comes from God, so he actually took upon him human feelings, as far as the office which he had undertaken allowed. ... He was God, I acknowledge; but on all occasions when it was necessary that he should perform the office of teacher, his divinity rested, and was in a manner concealed, that it might not hinder what belonged to him as Mediator. By this weeping he proved not only that he loved, like a brother, those for whose sake he became man, but also that God made to flow into human nature the Spirit of fatherly love.
John Gill says:
and wept over it; touched with a tender concern for it, his natural passions moved, and tears fell plentifully from his eyes. This must be understood of Christ merely as man, and is a proof of the truth of his human nature, which had all the natural properties, and even the infirmities of it; and as affected with the temporal ruin of Jerusalem, and as concerned for its temporal welfare; and is not to be improved either against his proper deity, or the doctrines of distinguishing grace, relating to the spiritual and eternal salvation of God's elect; things that are foreign from the sense of this passage.
Bruce Buchanan, an OPC pastor, says:
We need to appreciate Jesus as the Mediatorial Prophet, Priest, and King of his church. It is not fitting to read every statement of Jesus (who is God the Son) during his humiliation, as if he always speaks in his full capacity as the Ascended Lord, according to all his combined powers in hypostatic union, the God-Man. Frequently he speaks as the King of visible-Israel. He has come for the good of this collective portion especially; and they (the leaders, and their followers) are in process of repudiating him who is given them for a blessing. Is this not truly and objectively sad?
The Man, Christ Jesus, is fully capable of appreciating how that rebellion and sin had blinded the eyes and hearts of so many pitiful people, who above all the rest of the people on earth had one of the most extraordinary opportunities to repent and believe in God's saving Promise, and yet refused to do so, and prevented others from doing so; Mt.23:37, "...and ye would not." I cannot think why such an epic tragedy should not wring tears of grief, of sorrow, of frustration, of rage from the heart of One who had a clearer understanding of how this all must eventuate than anyone around him.
Here is One perfectly aware of how the wrath of God will be earned by this "city," by her leadership and by those who persist in identifying with them. He also knows that their blindness is willful, self-chosen. Just because one man's participation is ordained by God and certain, does not mean that he does not also choose and embrace his destiny. This is just that difference between predestination and fatalism. The latter presumes a foiled free-will whose better aims were deflected, and whose better hopes were dashed.
If we only allow a Jesus who always sublimates his ordinary human feeling into a perfect expression of resignation and repose in the ultimate aims of the godhead, then we actually have a less-than-human Christ. We have no explanation for Jesus in Gethsemane. We do not have a sympathetic High-Priest, because his temptations were meaningless. We do not have One who weeps at the door of a tomb from which he intends to summon a dead man to life in mere minutes.
He wept to teach us to weep
Matthew Henry says:
That Jesus Christ wept in the midst of his triumphs, wept when all about him were rejoicing, to show how little he was elevated with the applause and acclamation of the people. Thus he would teach us to rejoice with trembling, and as though we rejoiced not. If Providence do not stain the beauty of our triumphs, we may ourselves see cause to sully it with our sorrows.
Piper, in the sermon quoted earlier, says:
First, Jesus’ mercy is tenderly moved. He feels the sorrow of the situation. This doesn’t mean his sovereign plan has wrecked on the rocks of human autonomy. It means that Jesus is more emotionally complex than we think he is. He really feels the sorrow of a situation. No doubt there is a deep inner peace that God is in control and that God’s wise purposes will come to pass. But that doesn’t mean you can’t cry. ... Jesus felt enough compassion for Jerusalem to weep. If you haven’t shed any tears for somebody’s losses but your own, it probably means you’re pretty wrapped up in yourself. So let’s repent of our hardness and ask God to give us a heart that is tenderly moved.
He wept so that later he might rejoice
Alan Strange, an OPC pastor, says:
Jerusalem was a mixed multitude containing both reprobate and elect, although many of the elect had not then come to Christ and would do so only at and after Pentecost. ... Given that many Jews will be gathered in, there is no small sense in which our Lord's compassion expressed here will have Jerusalem's deliverance in some sense as its fruition.
Similarly, Gill's commentary, quoted earlier, refers to Isaiah 66:10:
Rejoice with Jerusalem and be glad for her, all you who love her; rejoice greatly with her, all you who mourn over her.