Same situation in the US. I can buy NyQuil/DayQuil, or I can buy the pharmacy-branded version for a lower price. Here it's usually not such a dramatic difference; probably the pharmacy brand is a a 30-40% discount off the big-name brand.
> How is THAT legal
Why shouldn't it be? Companies are free to set prices to whatever the market will bear. In this case it's based on customer ignorance, which makes it feel icky, but I don't think that's a reason to legislate this sort of thing.
> and how are people so unaware as to actually buy it?
Yeah, I don't know. I do remember that, many many years ago, I didn't know about this, and would always go for the big-name-brand version. At some point I learned to look at the active ingredients and just buy the cheapest one that had the same ingredients in the same dose, but I don't recall when or why I learned that, or why I didn't know that before.
I think there's also an implicit quality judgement sometimes, even if it's unfair. When it comes to groceries, say, canned tomatoes, and I see some fancy-looking Italian brand that I've heard of, my brain will automatically rate it much higher than the grocery store's own branded version of it. Maybe that's an effect of marketing/advertising, maybe it's something else, I don't know. And sometimes it's actually true: tomatoes are not all created equal. I think something similar happens with drugs, even if it's an entirely different kind of product.
People also often assume that something that costs more is automatically higher quality. For some types of things, that can be true (because yes, there is such a thing as a better tomato, and sometimes it costs more to cultivate said better tomato), but for drugs in a regulated environment, that doesn't really make sense. But people pattern match on what they know and what they feel.