It's about protecting the brand. They want the brand to be associated with rich people and the stylish. The way you do this is by making it more exclusive.
That means occasionally they are going to piss off someone who turns up dressed like a wreck but is willing to spend money. But these people are few and far between anyway, most of them will just be tyre kickers, when you kick a scruff out of an expensive shop the odds are that they would never have bought anything anyway.
The same with posh restaurants. They want to maintain the image as a place where the stylish and monied eat. If that means refusing entry to a few scruffs and losing a bit of money so be it. The posh don't want to be sitting at a table next to a bunch of ill mannered plebs and will pay decent money to avoid them.
If you want to be treated with respect then you have to jump through the hoops and look like you are the kind of person worthy of the establishment you wish to frequent/purchase from. If you want to buy a luxury car you need to look like you could afford one, not like you have just been dragged out of a river.
People may come up with their tall tails of how they were about to spend a hundred grand but then decided not to because of the attitude of the assistant, but these are what they are, tall tails and even if true are few and far between.
It does work kind of in reverse as well. A lot of nightclubs for example have certain dress codes, because of the kind of reputation they want and the crowd they wish to cater too and the culture they want to represent. Even if you turn up in your 10K suit or with your 20K handbag you still might not be let in because you don't fit the profile.