Here are some interpretive options that are valid in Catholicism as well as many other, but not all, Christian denominations.
Firstly, we don't need to rule out the possibility that the OT laws in question are perfectly just. But, we also know that God prefers mercy to justice; justice is the bare minimum. And, we can see this concept in Jesus' explanation of the similarly questionable OT divorce law:
1 He set out from there and went into the district of Judea
[and] across the Jordan. Again crowds gathered around him and, as was
his custom, he again taught them. 2 The Pharisees
approached and asked, “Is it lawful for a husband to divorce his
wife?” They were testing him. 3 He said to them in reply,
“What did Moses command you?” 4 They replied, “Moses
permitted him to write a bill of divorce and dismiss her.”
5 But Jesus told them, “Because of the hardness of your
hearts he wrote you this commandment. 6 But from the
beginning of creation, ‘God made them male and female. 7
For this reason a man shall leave his father and mother [and be joined
to his wife], 8 and the two shall become one flesh.’ So
they are no longer two but one flesh. 9 Therefore what God
has joined together, no human being must separate.” 10 In
the house the disciples again questioned him about this. 11
He said to them, “Whoever divorces his wife and marries another
commits adultery against her; 12 and if she divorces her
husband and marries another, she commits adultery.” (Mark 10:1-12)
In brief, God's OT commandments favored justice over mercy to accommodate the spiritual deficiencies of the culture. However, mercy is better than justice. And even in the NT, the OT law is still affirmed and accepted to some extent, but living according to the Holy Spirit, which is governed more by mercy than justice, is strongly preferred.
In the case of particular instances wherein God commands something that is seemingly harsh, wrathful, or less than the NT ideal of mercy, we approach one of two ways.
Option one. Recognizing that God's general commands (Mosaic Law) "meet people where they are" and allows for our hardness of hearts, we can reasonably assume that God's individual commands are likewise. When God speaks, he always meets us at our current spiritual state and will always mandate something better than we'd do on our own, but not so great than we'll think God is a joke and ignore Him. (More or less.)
Option two. We recognize that understanding written scripture requires a contextual lens, a basic understanding that Christ crucified is the heart of scripture, and the guidance of the Holy Spirit. With the contextual lens in particular, you don't need to assume a precisely historical read in these cases. And the relation of all scripture to Christ crucified then sheds light on the intended meaning of these types of passages. So you can assume one of a few basic scenarios (two of which I can recall!):
- When Person X is recognized to be a sinner and can be rightfully put to death according to the law, God commands their death in that specific case. The literal account may not be, "according to the law" but rather "God said." And while this may seem dishonest to us, it's not necessarily untruthful either. It's simply "connecting the dots" in a sense.
- God calls Person or Persons X "abhorrently sinful." God says, "have nothing to do with Person or Persons X on account of their behavior. Remove them from your presence." In OT contemporary literature, this might have been recorded is a more extreme and graphic retelling -- "God said, kill the sinner." And it's important to note, this isn't an infringement on the infallibility of scripture, which is not always, if ever, meant to fit into the genre of history. Rather, when the OT says, "God said kill sinner X," it often doesn't matter whether this is a literal retelling; the point is, the sin of sinner X is extremely terrible, and probably damning if serious action isn't taken.
Option three. We recognize, particularly in a more literal interpretation, that God is omniscient and omnibenevolent. As such, God may sometimes recognize a person's or people's relationship with Himself has become so endangered that he must take or mandate seemingly wrathful or lethal action to communicate the severity of the situation. In such cases, one could assume that God, in his perfect knowledge, knows that such actions are absolutely necessarily to save some or all of those involved without infringing on their free will. (The inspiration for this option is from Mike's answer. And as Mike's answer reminds us, the orientation of Mosaic Law to God makes adherence to Mosaic highly special and important in the "legal" arena.)