Is it legal to look through your phone or computer? No, unless they have your authorization. Can a school ask to look through your phone or computer? Yes, it depends on the school but some schools will have specific policies that require a student to be forthright in participating in a school investigation.
If a student were to refuse to provide access to their phone or computer, although this is somewhat of a gray area, the school can potentially charge them with, say, not complying with an investigation or whatever applicable charge would be appropriate to those circumstances. Unless the school has a search warrant, they're not legally able to look through your phone or computer, again, without your authorization. If you refuse to do so if the school asked out, can it lead to further problems?
Potentially, are you within your rights to refuse to do so? Also, potentially yes. In a case involving another student or other students that may have access to records on their own, if you sent text messages or emails or whatever the case may be to another student, you have to be mindful of the fact that they very well have those same records and could provide them to the school. It is a highly nuanced consideration and a lot is at stake. Having an experienced attorney-advisor will be your best ally to help you understand and navigate the process.