Does the valve have to be straight when replacing a tube?
It should be straight out, perpendicular to the rim. Otherwise you risk damaging the tube.

When the valve stem is at an angle the valve isn't free in the hole – it is trapped by the edges of the hole where they bind the stem. The edges of the hole may cut the stem which will be moving a little bit as the tire and tube flex over bumps and the like.

There will also be an area of the tube that isn't supported by the rim (or that is stretched more than the rest of the tube) near the valve stem. That area is likely to be a weak point in the tube.

And one more thing! As pointed out in the comments below, there are conditions – such as the tire moving on the rim – that are likely to further stress the tube as it passes through the valve hole. If the valve is initially straight any angle of the valve is an immediate sign that something is happening.