In Matthew 25, Jesus starts by giving the lesson of the 10 virgins, 5 of whom were wise and prepared for the Bridegroom’s return, but 5 were foolish and their lamps ran out of oil. While they went out to buy more, the Bridegroom returned. As a result, when they finally got back from trying to find more, it was too late. The door was already closed and locked.
Jesus follows that with the story of the “evil and slothful servant”, who along with his fellow servants, were given talents by their master. But, instead of putting it to good use that would earn a profit for his master, he buried it out of fear of losing it, and was punished severely.
Both of these parables are lessons about the responsibility of the followers of Christ to remain in a state of grace by living a good and holy life, while awaiting the day when they will face Judgement, and receive their just reward.
In part, Haydock explains verse 46 this way:
“Ver. 46. Everlasting punishment. The rewards and torments of a future life are declared by Jesus Christ, who is truth itself, to be eternal. Let no one be found to argue hence against the goodness and mercy of God, for punishing sins committed in time with punishments that are eternal. For 1. according to human laws, we see forgery and other crimes punished by death, which is in some measure an eternal exclusion from society. (SIDE NOTE: in modern times this might best be compared to the sins of a serial killer. Telstar) 2. The will of the sinner is such, that he would sin eternally if he could; it is an eternal God, a God of infinite majesty, who is offended. He essentially hates sin; and as, in hell there is no redemption, the sin eternally continuing, the hatred God bears to sin must eternally continue, and with it eternal punishment. The doctrine of those who pretend, with Origen, to question the eternity of the duration of hell’s torments; who can say with him, video infernum quasi senescentum, must encourage vice and embolden the sinner; for if the conviction of eternal torments is not capable to restrain his malice, the doctrine of temporal punishment would be a much less restraint.” (emphasis mine)
In Matthew 18 and several other places in the Gospels, Jesus uses hyperbole to exaggerate His utter disgust for serious sins that cause scandal among the people of God, especially for those that cause scandal to the “innocents”. He despises anything that causes scandal.
Those two situations are very different.