How can Christian theologians say that God is perfectly
merciful if he still punishes some people? Wouldn't he be more perfectly merciful if he forgave everyone?
No. The word "perfect" can be taken in different senses. Sometimes it means "completely" or "in every case." If this were the sense in which God were perfectly merciful, then he would forgive sins in every single case, thus forgiving everyone. But "perfect" has other meanings--for example, it can also mean "in the best way."
Suppose a person needs $25 to get out of trouble, and he comes to me for help. I know that if I give him the $25 he will get out of trouble, learn his lesson, and all will be well. I also know that if I give him more than $25 he will not learn his lesson but will use the extra money to go out and get in trouble again. How would we regard the act of giving him $25 versus a larger sum?
Assuming I do not owe him any money, giving either amount would be an act of generosity, but which act would be the more perfect example of generosity? From one perspective we might reason that giving the higher amount would be more generous and thus more completely or "perfectly" generous. From another perspective we might reason that by giving the lower amount I would be helping him more and thus would be more perfectly generous (generous in a better way).
This gives us an insight into the nature of virtue. To do something virtuously is not just to do it in a higher degree, but in a better way.
God is perfectly merciful in that he perfectly displays the virtue of mercy. This means that he is merciful to the right people, at the right time, to the right degree, with the right motive, and in the right circumstances. But some people and some circumstances are not the right ones. It is not appropriate to forgive a person's sins when he is defiant and unrepentant. It may be appropriate to continue trying to lead him to repentance, but it is not fitting for him to be forgiven even before he has admitted he was wrong.
God is perfectly merciful in the sense that he is merciful in the best way, not in the sense that he forgives every single sin people commit. Some sins (those of which people have not repented) are not appropriate to forgive, so God's mercy is the very thing that prevents him from forgiving them.