Q: If a witness caused his fellow a loss by withholding testimony on his behalf or by testifying against him inappropriately, is he liable?
A: A witness who has the knowledge to testify has a mitzvah to testify on behalf of that party in beis din. If he withheld testimony and caused a loss, he is not legally obligated to pay since he did not actively damage, but he still has a nonenforceable liability (chayav b’dinei shamayim) as grama (C.M. 28:1; Pischei Teshuvah 28:4).
A person should not testify in a secular court unless the case was authorized to be tried there by beis din; otherwise, there will be a chillul Hashem if he refrains from testifying. Nonetheless, if a witness testified truthfully in a secular court, even in a manner prohibited by halacha, he is not liable for the loss he caused (28:3).
However, if a person testified falsely and caused a loss, he is liable to pay, even upon his own admission, as a form of garmi. Some maintain that if the witness retracted his testimony before the defendant paid, even if his retraction was disregarded by the beis din, he is exempt (C.M. 29:2; 38:1. See also Shach 38:1 and Pischei Teshuvah 38:1).