The fact that people still buy them at the high price justifies the high price. Xeons by and large sell to businesses, and businesses aren't nearly as cost-sensitive with server equipment as you or I are with our equipment. Paying an extra thousand bucks for Xeons over the cost of comparable Core i7s or AMD processors is a big deal to us, not so much for businesses, especially large businesses.
ECC RAM is more expensive because it contains an extra memory module per rank (9 vs. 8) as well as sells a lot fewer units than non-ECC RAM. A product with a smaller market largely made up of people willing to spend more money (businesses) supports higher prices. Unbuffered ECC RAM is about a third more expensive than standard unbuffered non-ECC desktop RAM, and the only-for-servers registered ECC RAM runs about twice as much as unbuffered non-ECC desktop RAM. Again, that's because the only units using registered RAM today are servers that run a lot of RAM and cost 10-300 times as much as your average desktop computer.. Those are bought by companies with deep pockets that accept the high cost in order to get the products they want.
There are different tiers of testing performed, and testing on quality non-ECC desktop stuff and ECC server stuff is supposedly similar. Where the difference lies is that there isn't much lower-grade ECC RAM on the market, but there is for desktop. All of the server stuff I've seen is fully tested branded parts, while there are also unbranded but fully tested parts (ETT), unbranded untested but presumed working parts (ETT) and subpar parts (downgraded) for desktop/laptop RAM modules. See
here for more details on that.