So let's say that a Cleric and a Wizard are in combat, and the Wizard wins initiative. In the first round, the Wizard casts Magic Missile, and then the Cleric casts Spiritual Weapon. In the next round, the Wizard casts Mirror image. Would the Cleric have to roll to discern whether the Spiritual Weapon has the correct target, or was the Spiritual weapon already "locked on" to the correct target?
The Spiritual Weapon does not have any feature to see through illusions, detect enemies in any way, or counter defences that make an enemy harder to hit.
There is no rule about Spiritual Weapon "locking on" - in fact if an enemy moves away you have to move the Spiritual Weapon to keep up on your turn. It only moves/attacks when you spend a Bonus Action to make it do so.
The in game effect of Spiritual Weapon is a melee spell attack on a Bonus Action that you get to make at a distance. Pretty much all effects that could cause you to have difficulty hitting, such as not being able to see the target, any spell defences - including Mirror Image - apply as normal. Some of them, such as cover, apply based on the location of the Spiritual Weapon. Others, including visual effects, apply based on what the caster can see. If the caster could see through the illusion (or cannot see it), then they could direct the attack to ignore Mirror Image, otherwise the attack should use the rules under the Mirror Image spell and roll to see whether the true target or an illusion is targeted.
The spiritual weapon attacks would follow normal rules per mirror image.
The spiritual weapon spell description says:
When you cast the spell, you can make a melee spell attack against a creature within 5 feet of the weapon. On a hit, the target takes 1d8 force damage + your spellcasting ability modifier.
As a bonus action, you can move the weapon up to 20 feet and repeat the attack against a creature within 5 feet of it.
The spiritual weapon is not making the attack as a creature, you are making an attack with it.
The mirror image spell description says:
Three copies of you appear, moving in sync with you from the same space. Each time a creature attacks you, roll a d20 to see if it hits one of your copies instead.
An opponent is immune to the effects of this spell if it can't see, relies on other senses to perceive the world, or if it can see through illusions.
The sentence about an opponent being immune to the effects of mirror image if it can't see is not relevant here because the Cleric, who can see, is the one making the attack.
So each turn, the Cleric would use a bonus action to move/attack with the spiritual weapon and roll an additional d20 to first determine if the attack is directed at the Wizard or one of the mirror images. Then the Cleric would roll the actual attack.