Your question, João, is very good, because it shows faith, humility and great submission to God, qualities that are rare in our days…
It could be rephrased as follows: “There are passages in the Old Testament that I do not understand, but if the Lord did so, it can only be good. I would just like to understand the wisdom that led Him to act in this way.”
The first thing to avoid is to consider that there are two “gods,” one in the Old Testament and another in the New Testament, or that the Most High changed His “way of being” with the Incarnation.
As St. James says, “with whom [God] there is no variation or shadow due to change” (Jas 1:17).
Let us consider that in the Old Testament there are moving manifestations of divine goodness: “Who is a God like Thee, pardoning iniquity and passing over transgression for the remnant of His inheritance? He does not retain His anger for ever because He delights in steadfast love” (Mic 7:18).
“Can a woman forget her sucking child, that she should have no compassion on the son of her womb? Even these may forget, yet I will not forget you” (Is 49:15).
The word mercy appears more than two hundred times in the Old Testament, to make it clear that God has always been “merciful and gracious, slow to anger and abounding in steadfast love” (Ps 103:8), and his longanimity with the chosen people is admirable, amid so many infidelities.
The difference with the New Testament lies in the pedagogy used with those hard-hearted people (cf. Mt 19:8). God wanted to show the ancient peoples the seriousness of sin, for their iniquities made them cruel to others and to their own countrymen.
The “regime of grace” (Rom 6:14), inaugurated with Our Lord Jesus Christ, had not yet begun.
Thus, the “harsh” passages of the Old Testament must be interpreted as infinitely wise actions of a benevolent God, who knows how to show the justice appropriate to each situation.