There isn't a single easy answer to this.
If you are a minor, and on a school trip, you are subject to all of the school's rules. Your parents may have signed a consent form that allows the teacher to monitor your activities. Under some circumstances, the teacher and principal might be, in effect, your temporary parents. That would give them the right to give themselves consent to search your phone, especially if there was already information or evidence that you had participated in violating rules.
However, there may be more (or less) to it depending on exactly where and how this took place.
I agree with Mr. Lincoln about the school's rules following you on a field trip, outside school hours, off campus, etc. And, yes, your parent(s), if you are under the age of 18 years old, likely signed a consent form that detailed the rules, expected code of conduct, etc. Another place that you may wish to look for information is your school's policy handbook/code of conduct. Many schools are posting its handbook online (either at the particular school's website and/or on the District's main website). Most likely, you will find that the answer to your question, which I suspect is that the principal had the right to do what he did under the scenario set forth above.
Note: I am not licensed to practice law in your state. I provide this response for general, information purposes only. This is not to be construed as legal advice. Consult appropriate legal counsel in your area.