Why Did Jesus tell Peter to put away his sword but tell the Levites to go through the camp and slay those who refused to repent?

Exo 32:26-28 Then Moses stood in the gate of the camp, and said, Who is on the LORD'S side? let him come unto me. And all the sons of Levi gathered themselves together unto him. (27) And he said unto them, Thus saith the LORD God of Israel, Put every man his sword by his side, and go in and out from gate to gate throughout the camp, and slay every man his brother, and every man his companion, and every man his neighbour. (28) And the children of Levi did according to the word of Moses: and there fell of the people that day about three thousand men.

And what do you make of these comments?

Those who engaged in this work of slaying, however painful, were now to realize that they were executing upon their brethren a solemn punishment from God; and for executing this painful work, contrary to their own feelings, God would bestow upon them his blessing. 1SP 252

How do we harmonise these things?

The mystery of the cross explains all other mysteries. In the light that streams from Calvary the attributes of God which had filled us with fear and awe appear beautiful and attractive. Mercy, tenderness, and parental love are seen to blend with holiness, justice, and power. While we behold the majesty of His throne, high and lifted up, we see His character in its gracious manifestations, and comprehend, as never before, the significance of that endearing title, "Our Father." GC 652.1

As we examine the cross we see that truly the ministration of death is glorious and ushers those who trust the promises of God into His Righteousness