The CBP would be laughed out of court if it said "we were searching this phone for copyright infringement" as bring in copyrighted works is not prohibited and people have large personal collections of lots of things on their devices. You need lots more than just the presence of copyrighted works to prove copyright infringement. If the CBP already has suspicions of copyright infringements occurring then looking for particular copyright material makes sense.
It the difference between bringing in the contents of you library of books (legal) and bringing in multiple copies of the same book for resale when you are not
the designated distributer (illegal).
There is however digital stuff that in not permitted to cross US borders, and yes, the CBP has the right to look for this both coming in and leaving the US. That depends on what it is not that it is copyrighted.