I've seen them attacking at range specifically if the attacked soldier is using plasma blade reaction fire (and facing the spider), which would instakill a full health combat blood spider at the highest difficulty even, so there'd be no way to attack. If that's not the case, as either the attacked unit isn't facing the spider, or it's a civilian, it attacks from an adjacent field.
Judging from your screenshot, the AI probably just reacts to whether reaction fire is to be expected, and not to the type of reaction fire. On other occasions, spiders seem to walk towards soldiers, then get reaction-shot, and stop, although they clearly didn't use their full movement points. Happens if soldiers with reaction fire are arranged in a way that it's impossible to attack one of them without lots of reaction fire, which would kill the spider.