Also, what could I have done to prevent this in the first place?
Don't use mitre joints.
I love mitre joints as much as anyone, but one has to be aware of why those mitre joints fail. When you built those frames you were undoubtedly careful to cut perfect 45 degree angles, proudly fit two pieces together and checked their fit with a square and proudly thought to yourself, "man o man, I am THE craftsman!" (I have done the same thing many times.)
One of the favorite responses in this stack is to comment on the shrinkage or expansion of wood across grain due to changes in humidity. Indeed, that is most likely what is at work in your window casings.
In a mitre joint the geometry changes when the width of the board changes. Sure, a right angle cut will remain 90 degrees (assuming the grain is parallel to one leg of the angle and the other leg is perpendicular to the grain). But if you measure the perfect 45 degree angle that you cut after humidity does its thing, it is no longer 45 degrees. Recall that both legs of a 45, 45 degree right triangle are equal in length. Now the legs of that formerly perfect angle are no longer equal and the actual angle might be as much as 1/2 degree, making the opening twice as wide or up to 1 degree, very noticeable.
In response to your suspicion that the movement is due to thermal expansion and contraction, you might be right. I did a little internet surfing and found that the coefficient of thermal expansion for for pine perpendicular to the grain is about ten times as much as parallel with the grain. (For oak, the two coefficients are almost equal to one another.) You commented that the interior door frames are giving you no problems. Perhaps because the interior temperature and humidity are relatively stable throughout the year, keeping the changes in the size of mitre cuts small enough to prevent opening of the joints. Of course, at the windows everything turns cold so the relative changes parallel and perpendicular to grain might be enough to cause the joint to open.
In the case of your windows, some sort of butt joint or lap joint would not develop the opening, but alas, would not be as cool as the mitre joint.