A police officer believed he needed to stun an elderly woman with dementia symptoms after numerous verbal warnings failed to get her to relinquish a knife, a jury has heard.