Only if it is a state owned (diplomatic) device. Without diplomatic protection, you can be can be charged with, depending on jurisdiction and circumstance, anything from evidence tampering, obstruction of justice, to contempt of court. Technical hacks to human problems are only viable when you are shielded by sovereignty.
Typically what I've seen is if something is policy before hand, then it's legal, such as retention policies for email. In this case to do something similar, you would need the phone to not retain more than 24 hours of information or similar or be jumped and have your devices forcibly taken a away and get into some sort of 5th amendment edge case where you don't have to give the contents of your mind / say anything.
You: "Sure, I can hand it over, but all data will then get wiped by the device automatically due to Google/Apple/Samsung's anti-theft hardware design and I don't have a choice in the software settings to disable that"
After that it's upto the Judge whether to proceed with the handover or not.
At this point, if the judge proceeds with the handover, it will be the judge who destroyed evidence.