How can a non-Catholic get into state of grace as understood by the Catholic Church? State of grace:


  Condition of a person who is free from mortal sin and pleasing to God.
  It is the state of being in God's friendship and the necessary
  condition of the soul at death in order to attain heaven.
  source


Now,


  We cannot merit anything supernatural if we are not in a state of
  grace. To argue the contrary is to argue for Pelagianism.
  Nonetheless, God does hear the prayer of the repentant sinner.
  
  ... but the prayer of the unrepentant sinner, who prays for something
  other than for the graces of conversion, is a prayer lacking in merit
  or efficacy it would appear. source


I know some Protestants who are sincere in their faith and I saw them deeply praying. But from the quote above I also know that even if they pray deeply they can't merit anything as they aren't in a state of grace because they are not taking part in God's divine nature according to some theologians and the Catholic teaching.

My question is, how can a non-Catholic obtain the state of grace as understood by the Catholic Church? Is it even possible without becoming a Catholic? Does it even make sense for a non-Catholic to pray for anything other than for a conversion to become a Catholic?
Generally, the Church declines to comment whether any given person is in Heaven or not — at least not without a laborious inquiry and at least two confirmed miracles — but there are paragraphs in the Catechism we can use to try and understand how someone outside the Church might attain state of grace and retain it.

977 Our Lord tied the forgiveness of sins to faith and Baptism: &quot;Go into all the world and preach the gospel to the whole creation. He who believes and is baptized will be saved.&quot;Mk 16:15–16 Baptism is the first and chief sacrament of forgiveness of sins because it unites us with Christ, who died for our sins and rose for our justification, so that &quot;we too might walk in newness of life.&quot;Rom 6:4; Cf. 4:25
978 &quot;When we made our first profession of faith while receiving the holy Baptism that cleansed us, the forgiveness we received then was so full and complete that there remained in us absolutely nothing left to efface, neither original sin nor offenses committed by our own will, nor was there left any penalty to suffer in order to expiate them.... Yet the grace of Baptism delivers no one from all the weakness of nature. On the contrary, we must still combat the movements of concupiscence that never cease leading us into evil &quot;Roman Catechism I, 11,3
979 In this battle against our inclination towards evil, who could be brave and watchful enough to escape every wound of sin? &quot;If the Church has the power to forgive sins, then Baptism cannot be her only means of using the keys of the Kingdom of heaven received from Jesus Christ. the Church must be able to forgive all penitents their offenses, even if they should sin until the last moment of their lives.&quot;Roman Catechism I, 11,4
980 It is through the sacrament of Penance that the baptized can be reconciled with God and with the Church:

Penance has rightly been called by the holy Fathers &quot;a laborious kind of baptism.&quot; This sacrament of Penance is necessary for salvation for those who have fallen after Baptism, just as Baptism is necessary for salvation for those who have not yet been reborn.Council of Trent (1551): DS 1672; Cf. St. Gregory of Nazianzus, Oratio 39,17: PG 36,356


So when a person is first  baptised, their sins — both original and voluntary — are removed from them. And, as the Church teaches, any one — Catholic or not — can effect a valid Baptism if they recite the correct formula with the correct intention:

1256 The ordinary ministers of Baptism are the bishop and priest and, in the Latin Church, also the deacon.Cf. CIC, can. 861 # 1; CCEO, can. 677 # 1 In case of necessity, any person, even someone not baptized, can baptize, if he has the required intention. the intention required is to will to do what the Church does when she baptizes, and to apply the Trinitarian baptismal formula. the Church finds the reason for this possibility in the universal saving will of God and the necessity of Baptism for salvation.Cf. 1 Tim 2:4

However, and this is important, Baptism does not remove one's inclination to sin; and after one sins again, they lose their state of grace and thereafter it cannot be restored to them without the Sacrament of Penance.
The Sacrament of Penance, on the other hand, cannot be validly conferred but by a Catholic priest (cf. Canon 965) and only to baptised Catholics or Orthodox, and ordinarily by individual confession. So, barring specific Divine intervention, a person who is baptised and subsequently sins cannot regain their state of grace unless they are received into the Catholic Church — or another Church with valid Sacraments — and subsequently receives the Sacrament of Penance.
Therefore, a Protestant who dies immediately or nearly immediately after being baptised can generally be considered as having died in a state of grace, even though they might have died outside the fold of the Church. Otherwise, a person will generally sin again and lose their state of grace, and be unable to regain it because the Sacrament of Penance cannot validly be conferred upon them — not least because they generally do not believe in the efficacy of that Sacrament.
That being said, the Church will hesitate to declare that these people are definitely damned because &quot;with God, all things are possible&quot; (Mt. 19:26) and it may be that God will, in His mercy, effect extraordinarily that absolution which He has given ordinarily to His Church through the Sacrament of Penance. Though because such a grace is extraordinary, it must not be counted upon, and the Church calls upon her separated brethren to come into communion and gain ordinary access to the wellspring of graces that is the Sacrament of Penance.