British Army civilian worker who stalked a North Yorkshire schoolgirl spent six months in a Taliban jail, York Magistrates' Court heard.