Refusing a research project and/or assignment because of personal convictions
Standard IANAL disclaimer (I’m speaking from anecdotal experience and could be very wrong).

I had a student who recently refused to work on a political dataset because of her political views. I could’ve told her that this was a material part of our work and she has to do it or I can’t advise her. I don’t think there would’ve been any repercussions to me if I did. Generally speaking, if an advisor doesn’t want a student the reasons why aren’t very relevant, it’s best to part ways.

Eventually I chose not to and assigned her to another project. Did her academic progress suffer as a result? Sure. She made a choice and is paying some price for it.

For funding/collaboration, I can hardly see what legal protections could exist. If you choose not to apply for a DARPA grant or work with anyone there, you can’t reasonably argue any grievance as a result. Say, if you’re up for tenure, saying that you didn’t secure any funding but that’s only because you refuse to work with DARPA sounds preposterous. 

A similar case goes for boycott movements (e.g. BDS). My field (computer science) has a very strong Israeli presence; if you’re a BDS supporter it may limit your future academic  prospects. No one can force you to collaborate with Israelis, but in some cases, it may become very difficult. 

In the end, nothing in life is free, and you need to decide how important are your personal convictions vs the price of following them.