Generally, a free admission to officers isn't immediately illegal, but its admissibility in court is a complicated matter. The key factor is whether it was obtained legally. Police must adhere to specific rules, https://panchanandshaw.com/blog/confession-before-police-is-it-valid/