A federal judge raised concerns at a hearing Monday about how much legal authority the government has to compel Apple Inc. to unlock a criminal suspect’s iPhone and access the user’s data.

The judge’s skepticism comes amid a national debate involving tech companies and the degree to which they can protect their customers’ privacy from government.

In...