Generally, a voluntary confession to officers isn't immediately unlawful, but its use in court is a tricky matter. The key factor is whether it was obtained fairly. Investigators must adhere to specific guidelines, https://panchanandshaw.com/blog/contempt-of-court-explained/