Federal officials this week heaped praise on Yahoo Inc. Chief Executive Marissa Mayer for the company’s cooperation in an investigation of the hacking of hundreds of millions of the site’s accounts.

It was rare recognition for Ms. Mayer, who came under increasing pressure with each additional disclosure about the 2014 security breach since she made it public last September.

The...