I would guess it's the same motivation the Taliban has for attacking U.S. installations in Afghanistan. They want the U.S. out. Earlier this year the British post in Benghazi and the Red Cross operation were abandoned after being attacked. The U.S. consulate and the CIA post were probably seen as obstacles to Al Qaeda or their Libyan cohorts from taking over.
I mean tactically. It wasn’t to kill, obviously. Leaving only one other explanation IMO - kidnapping.