During the course of a criminal investigation, police officers may believe that there is evidence on your phone. They could ask you for your consent to perform a search. After all, your phone is probably locked behind biometric data or a passcode, so they need you to give them access.
One key thing to remember at a time like this is that you are not obligated to let them look at your phone just because they ask. You can tell them no, and this isn’t going to result in further criminal charges or make your situation worse. You have no legal requirement to allow them to look at your device.
The solution for police officers, then, is that they can get a search warrant. If they go through the proper channels and get a warrant, then they may be able to unlock your device without your consent.
How else could they get the information?
If the police cannot get a warrant, an illegal search would be problematic because it could invalidate the evidence that they find. If they force you to unlock your device against your will, that evidence may need to be excluded from court.
As such, the police will sometimes look for other sources. For instance, maybe they want to read social media messages that they believe you sent from your phone. But those messages are likely also stored on servers owned by the social media company that you were using. In some cases, the police can serve warrants to these companies and get the data directly from them, so they never actually need to unlock your phone at all.
This can be a fairly complex part of a criminal case. Make sure you understand all of your rights and the legal defense options at your disposal.