This is a bug from native Warband and has been reported many times. Devs say they are unable to recreate it. Only known solution is to save your game just prior to entering the city or castle to attempt the rescue. After the rescue, if the prisoner turns hostile, quit without saving and exit to desktop. Restart your game, load the previous save and rescue the Lord again. 99% of the time, the Lord will not be hostile. Good luck.