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