Determining what causes wind direction in the dynamic troposphere of the Earth is not as straightforward as it may seem. Despite this, scientists have a good grasp of how factors come together to create both wind speed and direction. Regardless of the geographic scale and area, there are three primary forces which contribute to the cause of wind direction. Certain forces play bigger roles depending on scale and area, but this will give the basics to understanding what causes wind direction no matter the situation.
Blowing from high to low pressure, air always attempts to balance out the pressure levels. A high-pressure system next to a low-pressure system will cause wind direction to flow clockwise and outward toward a low-pressure system. The low-pressure system is what causes wind direction to flow counterclockwise and inward. This is also referred to as a cyclonic flow.
If air is always trying to balance out pressure differences, why doesn't the wind direction flow directly from high to low? This phenomenon is the Coriolis effect, defined by the National Weather Service as allowing the "calculation of the apparent effects on moving bodies when viewed from a rotating Earth." It is not really a force, though its actions resemble one. Describing its effect on the cause of wind direction is commonly done using the merry-go-round example. Imagine looking down on two children sitting on a counterclockwise-spinning merry-go-round, tossing a ball back and forth. Looking down, it appears the ball is moving in a straight line. The children would say it seems as if a force is deflecting the ball to the right of where it is thrown. The cause of wind direction deflecting is the same effect and is due to the Earth spinning counterclockwise below the wind. Greater Coriolis effect is seen closer to the pole regions, and in the southern hemisphere this deflection is to the left. Extremely small scales diminish the Coriolis effect, but it is a huge factor in mid-latitude systems' wind direction. Accelerating speed will increase deflection.
The final cause of wind direction is friction. Surface-level winds are mostly influenced by friction, as this is where wind encounters varying surfaces. If the wind blows into a building, it must cause a change in direction. It could rise above the building or go around it in either direction, but it will cause a wind direction change. Slowing down of winds by a rougher surface will also decrease Coriolis deflection, and acceleration over a smoother surface will cause the opposite.