To understand v19, we need to read & understand the pre-text/verses 15-20; which speaks about reconciliation of two brothers/brethren due to the sin committed by either of them "...thy brother shall trespass against thee" by the ways Jesus is instructing/giving it unto the 12 disciples.
As per the v15-17, there are brethren who don't reconcile in private "...between you and him alone" or even after providing evidences in the presence of other witnesses/church "...established by the evidence of two or three witnesses" & "...he refuses to listen even to the church".
So Jesus suggests to distance yourself from such folks "...let him be to you as a Gentile and a tax collector".
Matthew 18:15-17:
15 “If your brother sins against you, go and tell him his fault, between you and him alone. If he listens to you, you have gained your brother.
16 But if he does not listen, take one or two others along with you, that every charge may be established by the evidence of two or three witnesses.
17 If he refuses to listen to them, tell it to the church. And if he refuses to listen even to the church, let him be to you as a Gentile and a tax collector.
v18-19: Further, here Jesus suggests there is still a way "Again I say to you.." if both of them are in mutual agreement "...two of you agree on earth" to reconcile, then taking it in prayer - God will surely answer their prayer, as God doesn't want his believers to live in discontentment with each other.
18 Truly, I say to you, whatever you bind on earth shall be bound in heaven, and whatever you loose on earth shall be loosed in heaven.
19 Again I say to you, if two of you agree on earth about anything they ask, it will be done for them by my Father in heaven.
Words "bind" & "agree" here mean the same as permitting
v20: Jesus here, speaks about His presence among believers.
“For where two or three have gathered together in My name, I am there in their midst.”
v12-14: And if we dive in further of the pre-text/verses, we can clearly understand, that God doesn't like His sheep to go astray from Him.
12 “What do you think? If any man has a hundred sheep, and one of them has gone astray, does he not leave the ninety-nine on the mountains and go and search for the one that is straying?
13 “If it turns out that he finds it, truly I say to you, he rejoices over it more than over the ninety-nine which have not gone astray.
14 “So it is not the will of your Father who is in heaven that one of these little ones perish.
To get a better grip/understanding around such verses:
1 John 3:22
And whatever we ask we receive from Him, because we keep His commandments and do those things that are pleasing in His sight.
1 John 5:14
This is the confidence which we have before Him, that, if we ask anything according to His will, He hears us.
Commentary Support: studylight.org
Expository Notes of Dr. Thomas Constable
The restoration of a wayward disciple v18:15-20
Jesus proceeded to explain what a humble disciple should do when a
brother or sister disciple has wandered from the Shepherd and the
sheep.
Adam Clarke
Matthew 18:19.
Again I say unto you — The word αμην, verily, is
added here, in ninety-eight MSS., (many of which are of the greatest
antiquity and importance,) seven editions, all the Arabic, the
Slavonic, and several of the Itala. The taking in or leaving out such
a word may appear to some a matter of indifference; but, as I am fully
convinced Jesus Christ never spoke a useless or a needless word, my
maxim is, to omit not one syllable that I am convinced (from such
authority as the above) he has ever used, and to take in nothing that
he did not speak. It makes the passage much more emphatic - Again,
VERILY I say unto you,
If two of you shall agree — συμφωνηστωσιν, symphonize, or harmonize.
It is a metaphor taken from a number of musical instruments set to the
same key, and playing the same tune: here, it means a perfect
agreement of the hearts, desires, wishes, and voices, of two or more
persons praying to God. It also intimates that as a number of musical
instruments, skilfully played, in a good concert, are pleasing to the
ears of men, so a number of persons united together in warm, earnest,
cordial prayer, is highly pleasing in the sight and ears of the Lord.
Now this conjoint prayer refers, in all probability, to the binding
and loosing in the preceding verse; and thus we see what power
faithful prayer has with God!
It shall be done for them — What an encouragement to pray! even to
two, if there be no more disposed to join in this heavenly work.
Bridgeway Bible
Lessons in forgiveness (Matthew 18:15-35)
Disciples of Jesus should be willing to forgive fellow believers who
sin against them, but they should also be concerned that offenders
realize their sin and turn from it. In each case the believer should
go to the offender privately and point out the wrongdoing, so that the
person might be spiritually helped. If this fails, two or three others
should be called in, firstly to make sure that the offender is in fact
guilty and secondly to appeal for reconciliation. If this also fails,
the entire community of believers should appeal to the offender.
Should there still be no change, believers should treat the offender
as if no longer part of their fellowship; though they should also
desire the person’s repentance and restoration (Matthew 18:15-18).
God has given his people the responsibility to deal with such cases,
and they must find out God’s will and do it. If they are to be
confident that their actions carry God’s authority, they will not act
in haste or out of personal prejudice. They have Jesus’ assurance that
as they talk and pray about the matter, he will be with them, silently
giving his guidance and help (Matthew 18:19-20).
Peter asked how many times Jesus’ followers should forgive before
taking the severe action that Jesus had just outlined. Jesus’ reply
shows that the severe action was not intended to be an alternative to
forgiveness. Believers do not take action against offenders out of
spite, but out of a concern for the offenders’ spiritual good.
Regardless of how many times offenders do them wrong, believers must
still forgive them (Matthew 18:21-22).
To illustrate the point, Jesus told a story. A king forgave a servant
a huge debt, but the servant then refused to forgive a fellow servant
a small debt (Matthew 18:23-30). When the king heard of his servant’s
behaviour, he withdrew his forgiveness (Matthew 18:31-34). The lesson
is that God will not forgive people if they do not forgive others
(Matthew 18:35; cf. v6:12).
P.S. If the reading or understanding of the v19-20 is done out of context then we are missing the whole dialect of the conversation, since v19-20 doesn't imply/suggest that His words are a promise to answer any prayer (regardless of its alignment with God's will); rather the prayer's context is for those brethren, who are in mutual agreement and wish to reconcile