The ninth commandment relates to justice, but before justice is done, innocence or guilt must be proven. But for innocence or guilt to be proved, the evidence must be confirmed by witness.
It is useful for the accused to provide additional evidence of his innocence by being prepared to swear on oath. God judges those who swear falsely, and commends those who fear an oath. If the Scripture commends fearing an oath, why does Jesus say: Swear not at all. Before I answer this, it must be understood that the New testament does not generally replace the Old. It builds upon it. It is therefore preferable to treat apparent contradictions, as qualifications rather than as changes in the law. God would not give a completely different set of rules for no apparent reason.
It is because it is reasonable for the accused or a witness to testify to innocence or guilt by swearing on oath. But it is not reasonable to expect answers to a multitude of trivial and often irrelevant and unfair questions to be sworn on oath.
Lawyers often make too much of irrelevant material, and by being very clever, can deceive the jury into thinking that they have evidence when it is meaningless. For this reason a defendant may try to avoid certain questions, and this does not imply dishonesty. But if the witness is forced to swear on oath, this is wrong. For example, if the defendant has been charged with assault, the lawyer could ask, Have you ever been angry with your dog? If as a child, when mopping the floor for Mum, the dog ran in out of the mud, then you are in big trouble if you have sworn on oath.
Therefore the solution is for the defendant to swear on oath to his innocence or guilt, but not to swear to the accuracy of the answers to every trivial question.