- Maybe the inmates don't like the PotentialFollowerFaction. Try removing your NPC from the Potential Follower Faction and see if that changes anything.
- Some script may be changing his aggression or factions when you enter the jail. Use console to confirm his aggression is what you expect. GetAVInfo("Aggression") should be 0, at most 1.
- As far as where a script might be triggered, it could be a trigger or it could be a story manager event node.
As far and Faendal attacking him: when NPCs are TEAMMATES, they are blind and deaf to everything in the world but the Player and other Teammates. So it sounds like Faendal has it out for this guy, but restrains himself until you dismiss him.
Finally, in addition to Aggression and Faction relationships, there is relationship rank. Two people can be a member of the same faction and still attack each other if their relationshiprank is low enough. I have had followers attack each other when dismissed because they hit each other with fireballs or area affect spells... which made them hate each other, but they restrained themselves until I dismissed them. So the question is: Is Faendal attacking the NPC, or is he attacking you? That is easy to test, just try releasing him before you enter the jail.