1 John 5:14-16 (RSV) And this is the confidence which we have in him, that if we ask anything according to his will he hears us. 15] And if we know that he hears us in whatever we ask, we know that we have obtained the requests made of him.  If any one sees his brother committing what is not a mortal sin, he will ask, and God will give him life for those whose sin is not mortal. There is sin which is mortal; I do not say that one is to pray for that.
The Navarre Bible comments on 1 John 5:16-17 as follows:
16–17. “Mortal sin”: the meaning of the original text is “sin which leads to death.” The gravity of this sin (St. John does not specify its exact nature) recalls the gravity of blasphemy against the Holy Spirit (cf. Mt 12:31–32) and of the sin of apostasy which Hebrews speaks of (Heb 6:4–8).
The Fathers have interpreted this expression in various ways, referring to different grave sins. In the context of the letter (in the previous chapters St. John often speaks about the antichrists and false prophets who “went out” from the community: 2:19) the best interpretation seems to be that of St. Bede and St. Augustine, who apply it to the sin of the apostate who, in addition, attacks the faith of other Christians. “My view is,” St. Augustine says, “that the sin unto death is the sin of the brother who, after knowing God by the grace of our Lord Jesus Christ, attacks brotherly union and in a passion of envy reacts against that very grace by which he was reconciled to God” (De Sermo Dom. in monte, I, 22, 73).
If St. John does not expressly command his readers to pray for these sinners, it does not mean that they are beyond recovery, or that it is useless to pray for them. Pope St. Gelasius I teaches: “There is a sin of death for those who persist in that same sin; there is a sin not of death for those who desist from sin. There is, certainly, no sin for the pardon of which the Church does not pray or from which, by the power which was divinely granted to it, it cannot absolve those who desist from it” (Ne forte).
Referring to this passage of St. John, Pope John Paul II says: “Obviously, the concept of death here is a spiritual death. It is a question of the loss of the true life or ‘eternal life’, which for John is knowledge of the Father and the Son (cf. Jn 17:3), and communion and intimacy with them. In that passage the sin that leads to death seems to be the denial of the Son (cf. 1 Jn 2:22), or the worship of false gods (cf. 1 Jn 5:21). At any rate, by this distinction of concepts John seems to wish to emphasize the incalculable seriousness of what constitutes the very essence of sin, namely the rejection of God.This is manifested above all in apostasy and idolatry: repudiating faith in revealed truth and making certain created realities equal to God, raising them to the status of idols and false gods (cf. 1 Jn 5:16–21).” And after referring to blasphemy against the Holy Spirit (cf. Mt 12:31–32) he adds: “Here of course it is a question of extreme and radical manifestations — rejection of God, rejection of his grace, and therefore opposition to the very source of salvation (cf. St. Thomas, Summa theologiae II-II, q. 14, a. 1–3) — these are manifestations whereby a person seems to exclude himself voluntarily from the path of forgiveness. It is to be hoped that very few persist to the end in this attitude of rebellion or even defiance of God. Moreover, God in his merciful love is greater than our hearts, as St. John further teaches us (cf. 1 Jn 3:20), and can overcome all our psychological and spiritual resistance. So that, as St. Thomas writes, ‘considering the omnipotence and mercy of God, no one should despair of the salvation of anyone in this life’ (Summa theologiae, II-II, q. 14, a. 3, ad 1)” (Reconciliatio et Paenitentia, 17).
St. Paul wrote:
1 Timothy 2:1-4 First of all, then, I urge that supplications, prayers, intercessions, and thanksgivings be made for all men,  for kings and all who are in high positions, that we may lead a quiet and peaceable life, godly and respectful in every way.  This is good, and it is acceptable in the sight of God our Savior,  who desires all men to be saved and to come to the knowledge of the truth.
This is a clear biblical teaching, and the interpretation seen above is harmonious with it, since 1 John 5:16 is not an absolute prohibition.
In biblical hermeneutics, we interpret the less clear passages in light of the clear ones. This, I submit, is an instance of that. Paul lays out the notion that we are to pray for all men, and specifically mentions kings (which would include extremely wicked people like, in his time, Nero!). We do so because God wants us to, and He does because He “desires all men to be saved.” 1 John 5:16 does not necessarily contradict this.
I think one way to look at that passage (just my speculation) is as a matter of emphasis, in a world where we don’t all have unlimited time. Given that, if we are praying, then there are prayers that are relatively more likely to be efficacious. Those far less likely to be efficacious are ones that have to do with people in grave, mortal sin, up to and including being separated from God.
Scott Hahn in his Ignatius Catholic Study Bible (in line with the thought of Pope St. John Paul II, seen above), thinks that the sort of sin referred to in 1 John 5:16 is “probably ‘apostasy'”. This may and likely does tie into the unforgivable sin or the sin against the Holy Spirit: outright rejection of God.
St. John says, in effect, “I am not commanding you to pray for that sort of person.” But the lack of a command or a necessary duty does not exclude or preclude or forbid prayer for such a person. St. Paul’s related passage, on the other hand, is such a command, applied universally to all men.
I think that settles it. We are to pray for all men, no matter how sinful or wicked or evil or rebellious against God. But because of lack of time and an abundance of needed prayers, sometimes perhaps we would place less of a priority on praying for those who are engaged in the unforgivable sin. I think that is what St. John is expressing, since it is harmonious with what Paul teaches in 1 Timothy 2.
Photo credit: The Virgin in Prayer, by Giovanni Battista Salvi da Sassoferrato (1609-1685) [public domain / Wikimedia Commons]