It depends, like so much in the game. Get Assista is right about the accuracy.
Night Combat: Japanese torpedo accuracy goes way up at very close ranges. There is a pretty consistent pattern that Japanese forces will try to close to 2000 yards to discharge their torpedoes. The AI appears to weight the relative strength, leader aggression, naval skill, etc. and make a decision whether to open range and break off or slug it out. A shell hit might get lucky and score a critical hit, but a ship that gets hit by a "Long Lance" is lucky not to be on the edge of sinking (unless its a battleship and even then they can only handle a few). If you're a Japanese player looking to repeat Savo Island, pray for bad weather and engage under a new moon. That virtually guarantees 2000 yard engagement ranges in short order.
Day Combat: Relative strength, task force mission, speed, and leadership again play a big role. A transport force will aim to flee. Inferior forces tend to try to flee, but again, Japanese forces tend to try to close to try and take torpedo shots before disengaging. I don't often see the Japanese closing to less than 8000 to 10,000 unless they have a massive advantage. I've alsp seen cases where one side will attempt to break off (there is brief message that flashes up on the surface combat screen) and then an engine hit might slow down a major unit of the disengaging force. Then instead of opening range to break-off, the opposing side might end up closing again. Once a sides has shot through a lot of their ammunition, then there is an attempted break-off. Historically, about the only action that ended that way was the Komondorski Islands in 1943.
One slightly disappointing thing is that even in nearly point-blank night engagements, "deck armor hits" still happen in absurd situations, e.g. US DD vs. IJN capital ship. I don't have a good explanation for that.
Another point is that close range can let a ship punch above its weight. A US cruiser can score a belt penetration hit on a Kongo class if the range is close enough (2000 yards for a 6" gun and 3000 to 4000 yards for an 8" gun). It is rare and not a practical tactic, but I've seen it.