Williams received a code violation for coaching, a penalty point for racquet abuse and a game penalty for calling the umpire a "liar" and a "thief" during her defeat by Naomi Osaka, BBC Sport reported.
Federer said the incident could have been handled differently.
"I feel like Serena should have walked away," he told the Sunday Times.
"She did, but she went too far. She should have walked earlier."
Federer did, however, say Williams' actions were "a little bit excusable".
He added, "The umpire maybe should not have pushed her there. It's unfortunate, but an incredible case study."
Osaka's 6-2 6-4 victory over Williams on September 9 was overshadowed by the American's outbursts during the second set.
Williams, 37, was given a first code violation after umpire Carlos Ramos judged a gesture from coach Patrick Mouratoglou to be coaching.
The American – a 23-time Grand Slam singles champion – told Ramos she would "never cheat to win and would rather lose".
Mouratoglou later admitted he had been coaching from the box.
Williams received another code violation for smashing her racquet, leading to Ramos docking her a point.
When the game finished, she called him "a liar" and "a thief". That led to Ramos docking her the next game – leaving Osaka needing just one for victory.
Williams later said it was "sexist" to have been penalized a game.
She was fined $17,000 (£13,100) by the United States Tennis Association for the code violations.