The first opportunity you have to unlock this is Mission 2.
To swap weapons with a Marine you need to first not have the same weapon as them as either your primary OR secondary
, then walk up to them and press and hold
Part way through Mission 2 you will be told that some Marines are stranded and need rescuing, find them and this will be your first opportunity to swap weapons with an ally.This can be unlocked on any difficulty and at any time you see a marine in campaign
Here's a video demonstration of the part of the level in Mission 2.