The number that matters is the distance between the stays, together. Easier to measure at the frame with the wheel off. And then, your aftermarket wheel has to match that.
You measured a 5mm difference on one side. That could be a 142mm rear end versus a 146, with the 1mm difference from your measurements made up on the other side. Another (more likely?) possibility is the difference is Boost vs. Non Boost. Boost is 12x148mm, while a non Boost hub is 12x142. 6mm difference.
What is your bike and what is the web site for the aftermarket wheel? This sounds like a mistake on the spacing of the wheel purchase.