In the Director's commentary, Andrew Stanton described Eve as being the "porsche" of robots, containing every possible feature, regardless of the cost or potential for use. This would logically include the most advanced weaponry available.
"She's the highest, most expensive, no-expense-spared kind of project
that the Buy'n'Large corporation could use to make a probe droid.
She's so advanced that we don't even understand how she can float and
how these appendages can magnetically be close to one another and
things can separate, but it feels like it had a logic behind it"
Since EVE's primary purpose is to travel to Earth and conduct a plant survey as part of the (classified) Operation Recolonise, it's reasonably clear that B'n'L intended for her to deal with any problems that she's likely to encounter. This would include anyone or anything that might prevent her from completing her vital mission or attempt to force her to reveal classified information. Potential foes could include humans from other spaceships, rogue robots or simply things that get in her way.
As to why she's so trigger-happy, this is covered in the crew commentary between Derek Thompson (story artist), Bill Wise (character supervisor) and Lindsey Collins (co-producer). Her hair-trigger response is apparently a mixture of sensible precaution and nerves.
Bill Wise: [Laughs] She has got a short fuse.
Derek Thompson: Yeah, she's temperamental
Lindsey Collins: Of course. She's sent to a bunch of different worlds. She doesn't know where she's going. You don't know what's out
Derek Thompson: If you were left in a tyre-yard, you'd be nervous.
Out of universe
The choice to arm Eve was evidently made by Pixar to enhance her clean lines, technical superiority and obvious femininity with a huge honking (and somewhat angular and masculine) cannon. From a dramatic perspective, this also serves to further distance her from the unarmed and wholly unassuming Wall-E unit that she encounters.
EVE’s sleek, minimalist design contrasts with the brown, muddy, ruined
Earth. In this juxtaposition, her simple cleanliness is exceptionally
beautiful — enhanced by the strength of her technical capabilities.
Concept Art: Eve Shooting Gun