Addition of acid to 3-methyl-2,3-dihydropyran When a general acid, H-X reacts with the alkene in an addition reaction, which regiochemistry is expected?

In addition reactions X attaches to the most substituted carbon whilst H bonds to the carbon with fewest alkyl groups. In this case I would believe the third carbon to be the most substituted carbon due to it being bonded to three other carbons. And the second carbon to be where the hydrogen will bond. However, apparently it should be the other way around. And this would be the compound formed:



Why is the second carbon the most substituted in this case? Does it have to do with oxygen being more electronegative and thus it is seen as a higher prioritized substituent?
Apparently, you're using the Markovnikoff's rule here. Recall that it is only a basic rule intended for simple unsaturated hydrocarbons, and fails at more advanced examples involving heteroatoms or rings.

In this case, the first step is the addition of $\ce{H+}$ ion from the acid to the pi bond, which leads to the formation of a carbocation. The carbocation's positive charge is most stable next to the oxygen atom. Can you tell why?

In the second step, the $\ce{X-}$ ion will simply attach at the position where the positive charge was the most stable, leading to a product as you've shown in the second image.