There are plenty of exceptions to the hearsay rule, though; there are also times when something that seems like it’s hearsay isn’t. Exception: maybe you made the statement to the cop while you were covered in blood and blubbering about something you had witnessed, making it an excited utterance. Or maybe your lawyer is eliciting the statement from the cop not to suggest to the jury that it’s true, but to show you had no motive, making it fall outside of the hearsay rule.
Police have a responsibility to testify truthfully under oath, within the constraints of the rules on hearsay. But that doesn’t mean they are forbidden from saying anything in your favor, no matter what.
Also if a cop lies hard to say who is right. But if you never talked to a cop unless your lawyer was present with recording equipment, etc. well, that’s a much more solid defense.
But it's unlikely the Police officer actually "witnessed" anything that'll help you.
If you tell police officer you did something bad, it's essentially a confession and reported as such.
If you tell police officer you did something good, it's hearsay - you told it to officer who told it to judge & jury.
Then there's jurisdictional details as to their role and rules of evidence etc that will vary from country to country.
But it's a shocking revelation to most people that Police cannot effectively help you in court. That's not their role.
-----------------------
Edit: Found it - federal rule of evidence 801(d)(2)(a) - Opposing Party Statement
https://www.uscourts.gov/sites/default/files/federal_rules_o...