Problem: This passage tells us that David “brought out the people who were in it, and set them under saws, sharp iron instruments, and iron axes, and made them pass through the brickkiln.” (2 Sam. 12:31). How can wholesale torture be justified like this?
Solution: The problem here is with a misinterpretation of the passage. The NASB (as a very literal translation) can sometimes miss the forest for the trees in its translation. That is, it can be sometimes too literal and miss the intention of the author. The NIV explains that David “brought out the people who were there, consigning them to labor with saws and with iron picks and axes, and he made them work at brickmaking.” Thus David was putting them to work—not to torture or kill them. By contrast, the Ammonites demanded the people of Israel to pluck out an eyeball for their terms of peace (1 Sam. 11:2)! Therefore, putting these Ammonites to work was mild by contrast.
Finally, even if this does describe torture, it isn’t prescribing it. Not everything that the Bible contains is necessarily condoned by God. Scripture contains the lies of Satan, but it doesn’t approve of them. That is, this passage does not command us to kill or torture others.