this is nothing to d with the law (or being "illegal") really. the shop must satisfy itself that whoever purchases age resrticted goods is the age they say they are, if your friend couldnt prove to THEIR satisfaction she was old enough, they did eactly the right thing by turning her down, or could have faced a fine.
As for you - well it sounds like you WERE trying to buy fags for someone THEY thought was underage, so i can see their point.
Shops, if they like could refuse to allow entr to people wearing yello jumpers, or peole with brown hair - they dont HAVE to sell to anybody