I am confused about how the next badge is generated. I found a post about it here. It said that the "Progress to next badge" bar automatically selects the badge you're closest to earning (or that's most logical to go to next). What does "most logical" mean? How does the system determine which badge is the most logical one?
You have answered your own question - the 'most logical' badge is the one that you are closest to achieving, or in other words the one you have progressed the closest to achieving.
One way I have noticed is if you calculate what % completion you are at for each of the badges. If there are 2 or more the same, then it is sorted by priority (gold, then silver, then bronze).
For example, one of mine:
Looking at the top row:
Fanatic and Proofreader are both at 77/100 or 77% complete, Fanatic is first because it is gold; Proofreader is second. Then in third place is Archaeologist, at 58/100 or 58% complete, finally for this example in fourth place is Marshall at 283/500 or 56.6% complete.
Observing the changes in my 'Select your next badge' screen tends to indicate to me that the % badge completion is the major part of the logic.