It probably can't? (But this whole scenario is wildly unlikely anyway, so it doesn't really matter)
Characters normally can't have an ability score above 20...
The general rules for ability score maximums are set forth in the "Ability Scores and Modifiers" section of chapter 7 of the PHB and basic rules (emphasis mine):
A score of 10 or 11 is the normal human average, but adventurers and many monsters are a cut above average in most abilities. A score of 18 is the highest that a person usually reaches. Adventurers can have scores as high as 20, and monsters and divine beings can have scores as high as 30.
This paragraph tells you a number of things about ability scores.
- First, 10-11 is the "average" score for humans in general. This
corresponds to a modifier of +0, and the commoner NPC statblock
seems to match this as well, having a score of 10 in all six
abilities. (Both of these facts also seem to fit the unstated
expectation that the rules are written in a way that treats humans as
the "default", common in the Material Plane of every official
setting, at least in 5e.)
- Secondly, a score of 18 is the highest that a person "usually"
achieves. It's not clear exactly what this is referring to or what
the purpose of this sentence is. If I had to guess, it's meant to to
the fact that 18 is the highest possible ability score value before
racial modifiers for a level 1 character (assuming the default method
of determining ability scores: roll 4d6 and drop the lowest die,
- The final sentence says that adventurers' ability scores can be as
high as 20, and that monsters (and "divine beings", possibly
referring to powerful NPCs that might not be considered "monsters")
can have an ability score as high as 30.
In my opinion, this last sentence (bolded in the quote above) is a clear statement of the general rule for PCs: Player characters have an ability score maximum of 20. Barring specific things that overrule this statement, these do describe the maximums for ability scores for adventurers and monsters/NPCs respectively.
The description of the additional Honor ability score option also alludes to the existing limit on player characters' ability scores and extends it to the new score as well (DMG, p. 265; emphasis mine):
Unlike other abilities, Honor can’t be raised with normal ability score increases. Instead, [the DM] can award increases to Honor—or impose reductions—based on a character’s actions. [...] As with other ability scores, a character’s Honor can’t exceed 20 or fall below 1.
This clearly implies that the regular 6 ability scores can't normally exceed 20 or fall below 1 either.
Rules designer Jeremy Crawford also noted in an unofficial tweet from September 2017:
Ability scores go no higher than 30. For regular folk, they go no higher than 20.
In essence, unless specified otherwise (by a class feature, magic item, or something else), the ability score maximum for a player character is 20.
...But there are specific exceptions to the general rule
You may have noticed my disclaimer earlier about "specific things that overrule this statement". The reason I note this, even though it's not mentioned in the quoted rule, is because of one of the fundamental rules of D&D - Specific Beats General:
That said, many racial traits, class features, spells, magic items, monster abilities, and other game elements break the general rules in some way, creating an exception to how the rest of the game works. Remember this: If a specific rule contradicts a general rule, the specific rule wins.
The question quotes the descriptions of a number of things in the game that don't ignore the general rule on a character's ability score maximum, and just a few things that do.
The general rule applies in most cases
Most things that increase an ability score are limited by the character's ability score maximum. For instance, the Ability Score Improvement class feature, the ioun stone of agility, and all the "half-feats" (which increase an ability score and also grant another benefit) all state that the ability score increase they grant can only bring the character to a maximum of 20.
In essence, they're reiterating the general rule on a character's ability score maximum, not making up a specific rule where no general rule exists. It's a redundant clarification, but one that is helpful to make when there are other items that do ignore or generally increase this maximum (as listed below).
Some stuff sets an ability score to a fixed value, ignoring your maximum
There are a few items that essentially disregard your normal score for a certain ability (along with your normal maximum for that score), and simply set that ability score to a particular value (unless your base score is already higher).
For instance, the gauntlets of ogre power simply set your Strength score to 19, unless it's already higher. Similarly, the belt of giant strength changes your Strength score to a value between 21 and 29, depending on the variety. (A potion of giant strength has a similar temporary effect.) The headband of intellect sets your Intelligence score to 19, and the amulet of health does the same for Constitution.
All of these items, however, only set the score to that value while attuned (or for 1 hour, for the potion of giant strength. More importantly, they don't interact with your regular ability score maximum in any way; they simply set your ability score to the specified value, unless your "true" ability score (i.e. your score without the temporary boost) is already higher - in which case they have no effect.
Things that specifically increase your ability score by a particular amount (e.g. ASIs, other magic items) only affect your base ability score, not the fixed value assigned to you by one of these items. Crawford confirms this interpretation in a series of unofficial tweets from August 2015. (Multiclassing prerequisites are also meant to be met by your base score tangentially related Q&A: Can multi-classing prerequisite ability score(s) be met through a magic item?)
Some ability score increases have their own limit, solely for that increase
As mentioned, the Star card from the deck of many things increases an ability score by 2; its description says the score can exceed 20, but can't exceed 24. This reiterates the general rule to explain how the item ignores it; if there were no general rule, there'd be no point to saying the increase can bring the score above 20.
Note, however, that as designer Chris Perkins explained in an unofficial tweet in December 2016:
It increases one ability by 2, to a maximum of 24. It does not increase your maximum for that stat otherwise.
In other words, the Star card doesn't actually change your ability score maximum going forwards; it only raises it (if necessary) to 24 for the increase granted by the card itself, and then your ability score maximum starts to apply again. For example, if your Strength score is 18, and the Star card increases it to 20, gaining an Ability Score Improvement feature later can't then increase your Strength further (unless something has actually increased your ability score maximum from 20 to something higher).
One of the benefits of the Book of Exalted Deeds says it increases Wisdom score by 2, to a max of 24. This is identical to the phrasing of Perkins' tweet above, in that it increases your current score (temporarily increasing the maximum solely for that increase, if needed), but doesn't change your ability score maximum otherwise.
(Ostensibly, if the Star card brings your score to 21-24 and that's above your ability score maximum, then your ability score after the card effectively becomes your new maximum. However, I'm not sure how that new maximum would interact with effects that reduce your ability score. That would be better asked as a separate question.)
Very few things permanently increase your overall limit
In contrast, there are only a few items that explicitly increase an ability score maximum in general. For instance, the manual of gainful exercise explicitly says (emphasis mine):
your Strength score increases by 2, as does your maximum for that score.
There are six such items with this sole benefit, one for each ability:
One of the benefits of the orb of the veil (Explorer's Guide to Wildemount, p. 268) is also identical to that of the tome of understanding.
If there were no general "ability score maximum" rule, the latter part of the quoted statement would be entirely meaningless.
In other words: If we assume that only the Ability Score Improvement feature (as well as other such ability score-increasing features or items) is limited to a maximum score of 20, and otherwise anything else can increase your ability score above 20 (as some other answers suggest), then what does it mean to "increase your maximum for that score" by 2? A nonexistent value can't be increased. If there were no general rule, it'd be easier to just leave off that part of the sentence entirely.
Thus, it's clear that characters do have a default ability score maximum of 20 for each ability score. That maximum can be increased or ignored/overridden by certain items if they explicitly say so, but otherwise generally functions as an upper limit on the character's ability score.
Crawford confirmed that this is how some of these exceptions interact in a series of tweets from March 2018:
If I use a Tome or Manual to go from a 19 to a 21 in a stat and increase my maximum, can I use a "half-feat" like Resilient to get to a 22?
If your ability score maximum is raised to 22, that means you can now raise that score to 22.
If you find multiple books or are long lived, can you get this bonus multiple times?
It wouldn't allow a creature to ignore the max cap of 30, however, would it?
The hammer of thunderbolts is sort of similar to the tomes in terms of how it works, but is a bit of a special case. In order to attune to it, you must be wearing a belt of giant strength and the gauntlets of ogre power. (As Crawford pointed out in an unofficial tweet from January 2018, the description of the hammer of thunderbolts doesn't say you have to attune to those two other items, merely that they must be worn.)
The relevant part of the description of the hammer of thunderbolts says:
While you are attuned to this weapon and holding it, your Strength score increases by 4 and can exceed 20, but not 30.
(As mentioned above, you may or may not be attuned to one or both of the belt of giant strength and the gauntlets of ogre power; since each sets your Strength score to a fixed value, and all variants of the belt set it to a higher value than the gauntlets. Normally, one would expect that the increase to your Strength score applies to your base score, rather than a fixed value set by a magic item - but Crawford clarified in another unofficial tweet from August 2014 that the hammer of thunderbolts is intended to increase your current Strength by 4, no matter how it is determined, so it would stack with the benefit of the belt if relevant.)
In effect, the hammer of thunderbolts sets your Strength score maximum to 30 instead of the regular maximum of 20 - but only while worn. (Again, it's reiterating that your regular maximum is 20; if there were no general rule limiting player characters' ability scores to 20, there would be literally no reason to explicitly mention "20".)
The increase to the Strength score is mentioned separately from the possibility for your Strength score to exceed 20; this suggests that your Strength score could be increased further up to the new limit of 30, if you haven't already reached that limit, as long as you are attuned to the hammer of thunderbolts. (Note that most things that simply increase your ability score would normally only affect your true score, not a score set by an item, but the phrasing seems to indicate that you do ignore your regular Strength maximum while attuned and treat 30 as your maximum instead.)
If this is correct, however, it's unclear what happens to anything that had increased your Strength score above 20 (or whatever your regular ability score maximum is) if you ever end attunement to the item. The most likely result would be that your current Strength score is once more reduced to your previous ability score maximum unless you attune to the item again. That said, the hammer of thunderbolts is a confusing outlier, and I may be partly wrong about how it's intended to work.
The barbarian's 20th-level feature, Primal Champion, is another special case of sorts; its description says (emphasis mine):
Your Strength and Constitution scores increase by 4. Your maximum for those scores is now 24.
It's very similar to the manuals/tomes listed above in that it explicitly changes/sets your ability score maximum for Strength and Constitution. However, it's different to the manuals/tomes in that it doesn't simply increase your ability score maximum by 4 regardless of its current value (if that was the intent, the phrasing could have matched that of the manual of gainful exercise). Instead, it simply sets your maximum to 24. (I assume there's an implied "unless your maximum is already higher" in there; the feature is obviously not intended as a nerf to 20th-level characters.)
Thus, the barbarian's capstone feature increases the character's ability score maximum for Strength and Constitution to a set value - assuming it's not already higher. If the character's maximum for Strength or Constitution is already 24 or higher, then the feature presumably is not intended to change/lower that maximum.
(Some DMs may house-rule that the feature increases the character's Strength and Constitution maximum by 4 no matter what their current maximum is, making it work like the tomes/manuals. This isn't supported by the wording of the feature, but probably won't substantially change the game - at least, it's no more game-breaking than letting the maximum go up to 24 to begin with, especially since other increases to one's ability score maximum are already powerful, and it's at level 20 anyway.)
Ability scores can never go above 30; there's no mechanics for it
Though the default ability score maximum of 20 for player characters can be modified by more specific things in the game, the listed ability score maximum of 30 for monsters is ironclad; there's no modifiers listed for scores above 30, and no official monster has any ability score above 30. Also, under the rules for creating a monster stat block, the section "Step 5. Ability Scores and Modifiers" reiterates the relevant rule (DMG, p. 274):
A monster can’t have a score lower than 1 or higher than 30 in any ability.
In fact, this extends to PCs as well - even the exceptions to a character's ability score maximum can't take you above 30, because the game does not allow for scores above 30 or below 1.
What about the bag of beans?
Now that I've rambled on for way too long about the general rules on ability score maximums - and about items that explicitly stick to the default, increase that value, or abide by their own restrictions - let's get to the bag of beans.
The description of the bag of beans says:
If you remove a bean from the bag, plant it in dirt or sand, and then water it, the bean produces an effect 1 minute later from the ground where it was planted. The GM can choose an effect from the following table, determine it randomly, or create an effect.
Row 81-90 of the subsequent table says:
A nest of 1d4 + 3 eggs springs up. Any creature that eats an egg must make a DC 20 Constitution saving throw. On a successful save, a creature permanently increases its lowest ability score by 1, randomly choosing among equally low scores. On a failed save, the creature takes 10d6 force damage from an internal magical explosion.
The question asks if the bag of beans can increase an ability score above 20. So, in order for that scenario to occur, all of the following conditions have to be met:
- Someone has a bag of beans (obviously)
- Whoever reaches into the bag manages to draw this specific kind of
bean, which requires that your DM either intentionally choose this
specific effect, or roll a d100 and get this result (of which there's
a 10% chance)
- You eat one of the 4-7 eggs (that you presumably know nothing about)
that springs up from this magic bean
- You pass a DC 20 Constitution saving throw (no easy task)
- All of your ability scores are 20 or higher before you eat the egg
(which seems virtually impossible in actual play unless you're
cheating to construct a contrived scenario...)
Now, if all of that somehow holds true... Then the only information the item description gives you is that "[the] creature permanently increases its lowest ability score by 1". There's no mention of an ability score maximum. However, as established in the rest of the answer, all characters do have an ability score maximum of 20 in every ability score by default, unless it is increased by some other effect. Since this item does not explicitly say it ignores or (temporarily or permanently) increases the maximum, it probably does not; thus, it can't increase an ability score above 20.
However, if all the conditions listed above were met, that means the DM has almost certainly contrived this entire situation solely to test this weird, tiny edge-case of the rules that I'm sure even the designers weren't accounting for... So at that point, do ability score maximums even matter? Do what seems fun.