What determines which character can be borrowed from an ally?

You can only borrow the hero that last lead your ally's party in the current game mode.

For example, if you were doing a Dark Side mission you could only borrow the leader of the team your ally used for their last Dark Side mission.

It is also true that whatever character you used as the leader in your last mission in the game mode won't appear in the list of possible allies.

Furthermore, there is a cooldown on borrowing the same hero from the same ally. The in-game hints say that it is 4 hours. Some speculate that it is possible to reset this cooldown by completing a challenge that does not allow the use of allies (such as Ability Materials, Training Droids, Credit Challenges, etc.)