Flexible casting allows you to create spell slots:
You can transform unexpended sorcery points into one spell slot as a bonus action on your turn.
These slots are treated no differently to the rules than normal spell slots.
The rules for learning spells say:
Each of these spells (you learn) must be a level for which you have
Since you have a 5th level slot, by a strict reading you could do this.
There are no other rules1 that I can find or think of that have any effect on the ability to do this, thus it seems to be permissible (or at least not explicitly excluded) by the rules.
It may not work depending on how the DM does leveling
There are no normal rules about when level up occurs, but many DMs allow leveling at the end of a long rest.
Since created spell slots vanish when you long rest, they would be gone before you could level and choose your spell.
Any spell slot you create with (Flexible Casting) vanishes when you
finish a long rest.
If your table levels after a long rest, then this strategy won’t work.
Almost certainly not intended (or at least planned for)
This is clearly a loophole use of the ability and is almost certainly not intended to work this way.
For example the following sentence of the rules about learning new spells says:
For instance, when you reach 3rd level in this class, you can learn one new spell of 1st or 2nd level.
This is referring to the spellcasting table for Sorcerer which outlines the slots a Sorcerer has at each level (and number of spells known). Note that there is no qualification here (eg “…unless some other feature grants you more slots”). The implication in the rules, though it is not explicitly stated, is that when the rules say “level for which you have slots” they mean “level for which you have slots according to the table“.
Probably not worth it
A DM can certainly allow this and I don’t think it would destroy their game alone (though I have not and likely will not ever play with this ruling). The exploit only seems to exist for 5th level spells so the impact, at least, is contained to that alone. In the end the sorcerer is trading almost all of their sorcery points just for the chance to cast up to two 5th level spells one level earlier. Even so, I would think hard before allowing it unless you think this will enhance the fun at your table.