Three Chinese traders earned more than $4 million in illegal profits after they hacked into the computer systems of prominent U.S. law firms and stole nonpublic information on mergers and acquisitions, according to a federal indictment unsealed on Tuesday.

The allegations are the latest alarm bell for law firms, which have long been considered vulnerable to cyberattacks.

The...