It is legal, though I can only speak to US law. Its just that the police can take it as evidence, and that makes the task of making it 'disappear' pretty simple. Some jurisdictions also require the officer to be made aware of the recording as it goes on.