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