Generally, a voluntary confession to officers isn't inherently unlawful, but its use in a trial is a tricky matter. The key factor is whether it was obtained legally. Police must adhere to specific guidelines, https://panchanandshaw.com/blog/confession-before-police-is-it-valid/