This is the AはBがC structure, and since it’s one of the basic structures in Japanese, you’ll probably see a lot of it. Basically, the grammar dictionary’s explanation is that “C says something about B, and BがC says something about A”. It goes into a bit more detail on that subject – along with a list of words that almost always use this form – if you’d like me to type it out. (Or find the last post I typed it out in and copy/paste. =P )
I feel like part of your confusion here stems from the fact that in English, “like” and “hate” are both verbs, but in Japanese, they’re adjectives. If it helps at all, you can think of them as “likeable” and “hateable”. So, “For middle-school students, high school students are detestable” kind of thing.
Sadly, I’m not really sure I can explain how the form came to be. Etymology! Something about B is the subject of the subordinate clause BがC.