Ahmad Al Aliwi Alissa bought the weapon on March 16, just six days before the attack at a King Soopers store in Boulder, according to an arrest affidavit.
Relatives described times when Alissa told them people were following or chasing him, which they said may have contributed to the violence, the official said.
AdThe shooting came 10 days after a judge blocked a ban on assault rifles passed by the city of Boulder in 2018.
That ordinance and another banning large-capacity magazines came after the 2018 mass shooting at Marjory Stoneman Douglas High School in Parkland, Florida, that left 17 people dead.
Supermarket employees told investigators that Alissa shot a man multiple times outside the Boulder grocery store before going inside, according to the affidavit.