Brilliant attacker McNamara, 22, was on Tuesday named in Australia's squad for the SheBelieves Cup, which includes matches against Japan, the United States and Colombia, later this month.
It is the three-cap Matilda's first call-up since returning from a third ACL tear.
McNamara scored in the third minute before Western United skipper Chloe Logarzo, who was overlooked for the Matildas, levelled the scores with a wonderful long-range strike in the 26th.
But McNamara tapped home in the 36th minute then completed her hat-trick with a wonderful chip two minutes later, before being substituted with apparent cramp in the 57th minute.
A HAT-TRICK FOR HOLLY MCNAMARA! �🪄— Ninja A-League (@aleaguewomen) @TheMatildas forward bags three goals in just 38 minutes. She just doesn't miss 🙌📺 Watch #MCYvWUN live NOW on Paramount+ or 10 Play pic.twitter.com/z1jZ7v2j6WFebruary 5, 2025
She now has six goals for the season, plus an assist, while City sit five points clear of second-placed Melbourne Victory.
Rhianna Pollicina, who assisted in two of McNamara's goals, added a fourth in the 59th minute, before Lourdes Bosch completed the rout in the 71st, ensuring City's first ever win over their crosstown rivals.
But there were concerns over United midfielder Melissa Taranto, who suffered a potentially serious left knee injury in the build-up to Pollicina's goal.
City opened the scoring when McNamara played the ball to Pollicina, who found her again with a wonderful through ball.
McNamara burst forward to get away one-on-one with Matildas goalkeeper Chloe Lincoln, who denied her first strike with an outstretched leg, before the striker controlled the rebound and buried her second attempt.
McNamara could have made it 2-0 in the 19th minute but took a loose touch as she charged towards Lincoln, who brilliantly blocked her attempt on goal.
Seven minutes later, City lost the ball under pressure and Logarzo unleashed a powerful, fizzing long-range strike.
That is some strike from distance!! 😮�💨🔥 CommBank Matildas star Chloe Logarzo gets on the scoresheet with an absolute cracker. — Ninja A-League (@aleaguewomen) @wufcofficial are back in it! 🟢⚫�📺 Watch #MCYvWUN live NOW on Paramount+ or 10 Play pic.twitter.com/10QkpJ58ZfFebruary 5, 2025
City goalkeeper Malena Mieres denied several United attacks, before Bosch went on a dazzling run down the right then cut the ball back for McNamara to tap home.
Two minutes later, Pollicina brilliantly found McNamara, who spotted Lincoln off her line and deftly chipped her.
Logarzo hit the crossbar in the 54th minute but five minutes later Mariana Speckmaier slipped through Pollicina to score, before Bosch added a fifth.
City travel to face Newcastle on Saturday while sixth-placed United play Sydney FC away on Sunday.