Missiles without any sensors on board will self destruct as soon as active sensor contact is lost.
If your missile has a sensor, it'll clear current target and move toward the last known target destination. If the sensor on board the missile picks up a target within range, that'll be the new target and destination. Turning your ship's sensor back on will not re-lock the missile back onto it's original target.