Legan, fatally shot by police within a minute of the attack, appeared to post a photograph from the festival on his Instagram account shortly beforehand, with captions expressing his disdain.
“Ayyy garlic festival time,” he wrote beneath a picture of people walking through the festival grounds. “Come get wasted on overpriced s***.”
Another photograph posted on Sunday showed a sign warning of a high danger of forest fires. Its caption urged people to read “Might is Right” – a racist and sexist treatise written in the 19th century.
“Why overcrowd towns and pave more open space to make room for hordes of mestizos and Silicon Valley white tw**s?” the caption said. The term “mestizo” refers to people of mixed race. The account was only a few days old, and was deactivated on Monday.
Donald Trump described the gunman as a “wicked murderer” following the mass shooting.
Police and FBI agents are still trying to determine a motive for the shooting and investigating unconfirmed reports by witnesses that Legan may have had an accomplice.
“It could have gone so much worse so fast,” Mr Smithee said, noting that the festival, which takes place about 30 miles southeast of Silicon Valley, is attended by thousands of visitors.
The police chief said that search warrants had been obtained for a home in Gilroy associated with the suspect and a car that officers believe he drove to the festival.
Investigators believe Legan – who was originally from Gilroy – purchased the rifle legally on 9 July in Nevada, where he had recently been living.
He was believed to evaded metal detectors and other security measures at the entrance by cutting through the fence, police said.
Legan killed two children and a man in his 20s, and at least 11 people were treated for wounds, according to Santa Clara Health System. Early police reports said that one person was in critical condition on Sunday.
The Santa Clara County Medical Examiner-Coroner identified the victims as Stephen Romero, six, and Keyla Salazar, 13, of San Jose, and Trevor Deon Irby, 25, of Romulus, New York.
The six-year-old child’s grandmother, Maribel Romero, described Stephen as a loving boy who was “always kind, happy and … playful”.
His mother and his other grandmother were also shot and were being treated in hospital, Ms Romero told media.
Founded in 1979, the Gilroy Garlic Festival is an annual event run by volunteers and held outdoors at Christmas Hill Park. The agricultural community bills itself as the “Garlic Capital of the World”.
Additional reporting by agencies