It was a temple tax, not a stranger’s tax.
see Matt 17:
24 20 When they came to Capernaum, the collectors of the temple tax 21 approached Peter and said, “Doesn’t your teacher pay the temple tax?”
25 “Yes,” he said. 22 When he came into the house, before he had time to speak, Jesus asked him, “What is your opinion, Simon? From whom do the kings of the earth take tolls or census tax? From their subjects or from foreigners?”
26 23 When he said, “From foreigners,” Jesus said to him, "Then the subjects are exempt.
27 But that we may not offend them, 24 go to the sea, drop in a hook, and take the first fish that comes up. Open its mouth and you will find a coin worth twice the temple tax. Give that to them for me and for you."
20 [24-27] Like Matthew 14:28-31 and Matthew 16:16b-19, this episode comes from Matthew’s special material on Peter. Although the question of the collectors concerns Jesus’ payment of the temple tax, it is put to Peter. It is he who receives instruction from Jesus about freedom from the obligation of payment and yet why it should be made. The means of doing so is provided miraculously. The pericope deals with a problem of Matthew’s church, whether its members should pay the temple tax, and the answer is given through a word of Jesus conveyed to Peter. Some scholars see here an example of the teaching authority of Peter exercised in the name of Jesus (see Matthew 16:19). The specific problem was a Jewish Christian one and may have arisen when the Matthean church was composed largely of that group.
21  The temple tax: before the destruction of the Jerusalem temple in A.D. 70 every male Jew above nineteen years of age was obliged to make an annual contribution to its upkeep (cf Exodus 30:11-16; Nehemiah 10:33). After the destruction the Romans imposed upon Jews the obligation of paying that tax for the temple of Jupiter Capitolinus. There is disagreement about which period the story deals with.
22  From their subjects or from foreigners?: the Greek word here translated subjects literally means "sons."
23  Then the subjects are exempt: just as subjects are not bound by laws applying to foreigners, neither are Jesus and his disciples, who belong to the kingdom of heaven, bound by the duty of paying the temple tax imposed on those who are not of the kingdom. If the Greek is translated “sons,” the freedom of Jesus, the Son of God, and of his disciples, children (“sons”) of the kingdom (cf Matthew 13:38), is even more clear.
24  That we may not offend them: though they are exempt (Matthew 17:26), Jesus and his disciples are to avoid giving offense; therefore the tax is to be paid. A coin worth twice the temple tax: literally, “a stater,” a Greek coin worth two double drachmas. Two double drachmas were equal to the Jewish shekel and the tax was a half-shekel. For me and for you: not only Jesus but Peter pays the tax, and this example serves as a standard for the conduct of all the disciples.