I heard a lot about what food goes well with some sauce or drink. Why does someone say that? Based on what? Do they only try those foods together or is there any sort of property on the food that indicates what it goes well with?
This question is very broad, but yes there are some general principles.
- Foods that grow together (geography) or ripen at the same time are often considered to go especially well together. Tomatoes, for example, are more often paired with basil or oregano than they are with other herbs. Pork and apples, for example, are not ready until the fall and grow in the same parts of Europe.
- Some meats are richer and fattier than others and are often served with an astringent red wine or an acidic (lemon, wine, vinegar, ...) sauce for contrast. This doesn't just make the food taste better, it's often more important the effect on how the wine tastes after eating different foods.
- Some proteins (such as fish) are softer and less chewy or crunchy than others, so they're often served with a crunchy starch - French fries instead of mashed potatoes, for example - or vegetable (coleslaw made with raw cabbage) for texture contrast. Others are chewy so they're served with mashed potatoes, again for a texture contrast.
- Some fish is light and delicate while other fish is stronger and oilier. You would use a different sauce with each and drink a different wine with each.
- Some combinations are traditional and people enjoy them whether there is science behind them or not - we put butter on mashed potatoes and sour cream on perogies, but there's probably no good reason we couldn't switch those pairings, for example.
- Some foods have more flavor than others and can stand up to a strongly flavoured sauce or drink. This is probably why people make pepper-crusted steak, but not pepper-crusted chicken. Some need to be enhanced by adding more herbs, spices and other flavourings.
Generally the recommendations come from either experiencing that exact combination (until you've tried ground black pepper on strawberries, you just will not imagine that it could be good, but it is) or from experiencing half of it - this sauce was great on that cut of beef, I think it would be even better on a particular cut of bison (because I know the similarities and differences in the meat and can imagine that combination.) The more different kinds of food you eat, and the more you think about what you're eating and why it's yummy or not, the better you will be at knowing the likelihood a particular combination will be good.
They say this because it is statistically very likely that, when a person with the same cultural background as the sayer eats the combination, that person will like what they eat.
This is not a restatement of your question: "A goes well with B" suggests that there is some quality in A and in B which determines how well they fit. But in fact, whether a person likes a thing is much more dependent on the person than on the thing. So, whether two foods go together depends on the eater, not on the food.
Kate Gregory already listed a few things eaters tend to like, but you can already see that it is a very mixed list. For example, she already mentions in point 3 that contrast can cause a good pairing, but in the last point, also says that similar levels of taste are considered a good pairing.
If you want to know why people like what they like, you need to ask a psychologist, not a cook. I have actually done research in that area (but not with a food focus), but explaining it in detail will take us too far from the topic of the site. For food taste (in general; not just for pairings), my observation is that there are two major drivers. The first is biological value: sugar, fat and to some extent salt are always liked, bitterness (which in nature is mostly found in alkaloids, which are frequently poisonous) is disliked. The second one is familiarity. In pairings, familiarity is the number one factor, my guess is that it makes much over 50% of the final judgement.
There are a lot of books/articles out there now that outline flavour pairings based on chemical components. While I agree with the original answer (great detail, carefully considered) I think food science (especially chemistry) deserves a bigger profile. Think of it like the periodic table of elements. There are only so many basic flavours, so you find matches in very strange places you wouldn't expect. Not a tasty example, but ever notice that cheap Parmesan smells a bit vomit-y? That borage flower (a common herb) tastes bizarrely like fresh oysters and cucumber-y? That's because they actually share important flavonoids. I guess chefs/food writers use this concept like painters use a colour wheel. If borage reminds tastebuds of oysters, maybe it would go well with the same ingredients that people traditionally pair with oysters, right?