So - I use an automatic bean-to-cup espresso machine. The grinder within the machine has 5 grind levels - 5 being the most coarse, 1 being the most fine. Out of the box, it was pre-set to 3, which did absolutely fine with the beans I initially used. But I've noticed recently that some of the cups have been really sour, and tasted as though they have been under-extracted. After changing the grind setting to 1 with the recent beans I was using, it tastes just fine again. Is it in my head or does the grind setting you should use really also depend on the beans you are using? If so, I am intrigued, why?
It's not just your head! Different roast batches will benefit from different grind settings.
In general, this is partly because different roast levels will result in beans that contain different compounds. This is because the heat or roasting causes chemical changes in some of the bean's compounds.
On the other hand, roasting causes water in the bean to boil off as steam. This process both affects the durability of the bean and the actual structure of the bean. First, a drier bean (resulting from a darker roast) is more brittle and is more likely to shatter, producing fines, during grinding. Second, the process of rapid boiling of the bean's water content caused a buildup of pressure inside the bean which makes beans "pop" during roasting, much like popcorn (but with coffee we call it "cracking"). Dark roasts tend to undergo two cracks during roasting, while light and medium roasts undergo one or stretch just into the beginning of the second crack. This process of crafting the bean create channels in the bean that expose more surface area in darker roasts right out of the roast, without any grinding at all. This structural change contributes further to the frailty of the beans and the likelihood of shattering during grinding.
This is essentially the reason why you see polar opposite recommendations from various coffee pros on how to grind light vs dark roasts.
People actually disagree on whether to grind light roasts more finely or coarsely than dark roasts. I don't want to suggest either approach. Rather, I just mean to explain that due to natural differences between bean harvests and differences introduced to roast batches via the cleaning, drying, and roasting processes, no two batches of coffee are quite the same. The differences become less pronounced with very dark roasts like you often find in coffee shops in the US, but when buying smaller batch coffee at home that isn't roasted quite so dark, you'll often find that two bags of the same brand and blend bought on the same day with the same roast date aren't quite the same and the one bag might do better with minor adjustments to your grinder between bags. And sometimes, especially when moving from one brand or blend to another, you'll see vast differences in your brew process using the same grind setting.
So yes, which grind setting you use depends on the beans you're using. Unfortunately, there's no great way to tell what grind setting to use until you do your first brew and observe the differences from what you expect. Just don't be surprised if you see big differences between bags or especially between brands/varieties.