I think the major driving force is machismo and competition. People I've met have into this sort of thing have an image of themselves as Matrix-style hackers. It's easy for business types to exploit that.
Be the best hacker working with the best hackers in the world.
I mean, there are people who work for ideological reasons instead(hackers working for FBI/MI5 despite low pay for instance), and in sure there are people in Israel who take this job to do the service to their country and such, and not just the salary.
IANAEG (...Not An Evil Genius), but it seems safe to assume that a lot of folks in that line of work do not share much of your worldview or value system, to need to do any "rationalizing" before doing such things.
(Actually, you might want to read a few works of fiction which feature well-written Evil Geniuses. Or some "I was a CIA agent..." biographies.)
".. Developing technology to prevent and investigate terror and crime"
I guess that their initial intentions were good, but a lot of clients (govs) abused it. It's still their fault for not acknowledging or putting breaks for these kind of actions.
1) money
2) the belief that if you don't build it then someone else will, so might as well be paid for it first
At least I imagine that's the only way people who build spyware and blockchain technologies can sleep at night.