It has to do with the stroke order of the part underneath it. For this example, I'll refer to as and , and as and . For , since the first stroke of the underneath part (the ) is horizontal, the is started with the horizontal stroke. For , since the first stroke of the is vertical, the is also started vertically.
Similarly for and . Since and both start vertically, the also starts vertically. Can't think of anymore off the top of my head where the starts horizontally. But the rule is to look to the first stroke underneath the .