In the old days, it was routine for customs officers to search ships coming in to harbor, including the effects of their passengers, to enforce importation laws. If customs couldn't do this, then importation laws would have no teeth, which is clearly not the intention of the constitution, which gives Congress the explicit power to enact and enforce them.
CBP argues that their smartphone and laptop searches were just an extension of that old custom, the court disagreed, ruling that a smartphone or laptop is fundamentally different from a ship's log or traveler's trunk, such that a higher expectation of privacy exists.