I love low-hanging fruit type questions I can actually answer. See the graphic below where I have simplified the wind flow with white arrows
The reason Palo Alto usually has NNW wind is the long NW to NNW oriented valley from the flats of San Jose over Morgan Hill to Dunnville. And this valley connects to the narrow valley heading towards the Pacheco pass over San Luis to the Central Valley.
When the ocean winds are NW and the pressure gradient is towards Bakersfield wind pours through the San Bruno Gap and curves as NW to WNW wind past Coyote and 3rd. Ave. as it is sucked towards the Altamont Pass area to the Central Valley. But part of that wind curves towards that long valley past San Jose. That curve makes the wind more NNW.
Because the marine air is dense, it takes these circuitous routes through gaps in the coast range. Think of it as sort of like molasses flowing through a maze of sugar cubes.
The winds in the Coyote to Palo Alto area often get more complex because of the SW facing Highway 92 gap that messes up all this flow unpredictably as 3rd. Ave. folks know all too well.