A criterion for HNN extensions of finite p-groups to be residually p